home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / desktop / mwfish.zip / SOURCES.ZIP / WMAIN.MOD < prev   
Text File  |  1991-06-27  |  90KB  |  2,128 lines

  1. (*#check(stack=>off,
  2.           index=>off,
  3.           range=>off,
  4.           overflow=>off,
  5.           nil_ptr=>off) *)
  6. IMPLEMENTATION MODULE WMain;
  7.  
  8. IMPORT Windows,WinStr,ApplDlg,ApplFish,Str;
  9. FROM Storage IMPORT ALLOCATE,DEALLOCATE;
  10. FROM Lib IMPORT RANDOMIZE,RANDOM;
  11.  
  12. CONST
  13. (* bitmaps *)
  14.   BUBBLE   =     5;
  15.   BUBBLE1  =     51;
  16.   BUBBLE2  =     52;
  17.   BUBBLE3  =     53;
  18.   STAR1    =     1006;
  19.   STAR2    =     1007;
  20.   STAR3    =     1008;
  21.   STAR4    =     1009;
  22.   STAR5    =     1010;
  23.   FLOOR    =     1011;
  24.   WEED1    =     1024;
  25.   WEED2    =     1029;
  26.   CHESTA   =     1041;
  27.   CHESTB   =     1042;
  28.   CHESTC   =     1043;
  29.  
  30.   FISHF1A  =     2000;
  31.   FISHF1B  =     2001;
  32.   FISHF1C  =     2002;
  33.   FISHF1D  =     2003;
  34.   FISHB1A  =     2004;
  35.   FISHB1B  =     2005;
  36.   FISHB1C  =     2006;
  37.   FISHB1D  =     2007;
  38.   FISHT1   =     2008;
  39.  
  40.   FISHF2A  =     2010;
  41.   FISHF2B  =     2011;
  42.   FISHF2C  =     2012;
  43.   FISHF2D  =     2013;
  44.   FISHB2A  =     2014;
  45.   FISHB2B  =     2015;
  46.   FISHB2C  =     2016;
  47.   FISHB2D  =     2017;
  48.   FISHT2   =     2018;
  49.  
  50.   FISHF3A  =     2020;
  51.   FISHF3B  =     2021;
  52.   FISHF3C  =     2022;
  53.   FISHF3D  =     2023;
  54.   FISHB3A  =     2024;
  55.   FISHB3B  =     2025;
  56.   FISHB3C  =     2026;
  57.   FISHB3D  =     2027;
  58.   FISHT3   =     2028;
  59.  
  60.   FISHF4A  =     2030;
  61.   FISHF4B  =     2031;
  62.   FISHF4C  =     2032;
  63.   FISHF4D  =     2033;
  64.   FISHB4A  =     2034;
  65.   FISHB4B  =     2035;
  66.   FISHB4C  =     2036;
  67.   FISHB4D  =     2037;
  68.   FISHT4   =     2038;
  69.  
  70.   FISHF5A  =     2040;
  71.   FISHF5B  =     2041;
  72.   FISHF5C  =     2042;
  73.   FISHF5D  =     2043;
  74.   FISHB5A  =     2044;
  75.   FISHB5B  =     2045;
  76.   FISHB5C  =     2046;
  77.   FISHB5D  =     2047;
  78.   FISHT5   =     2048;
  79.  
  80.   FISHF6A  =     2050;
  81.   FISHF6B  =     2051;
  82.   FISHF6C  =     2052;
  83.   FISHF6D  =     2053;
  84.   FISHB6A  =     2054;
  85.   FISHB6B  =     2055;
  86.   FISHB6C  =     2056;
  87.   FISHB6D  =     2057;
  88.   FISHT6   =     2058;
  89.  
  90.   FISHF7A  =     2060;
  91.   FISHF7B  =     2061;
  92.   FISHF7C  =     2062;
  93.   FISHF7D  =     2063;
  94.   FISHB7A  =     2064;
  95.   FISHB7B  =     2065;
  96.   FISHB7C  =     2066;
  97.   FISHB7D  =     2067;
  98.   FISHT7   =     2068;
  99.  
  100.  
  101.   FISH1X   =     71;
  102.   FISH1Y   =     40;
  103.  
  104.   FISHX1X  =     42;
  105.   FISHX1Y  =     36;
  106.  
  107.   FISHX2X  =     22;
  108.   FISHX2Y  =     22;
  109.  
  110.   FISHX3X  =     22;
  111.   FISHX3Y  =     22;
  112.  
  113.   F1X      =     72;
  114.   F1Y      =     71;
  115.  
  116. (* Options Menu Items *)
  117.   IDM_PLUSBUB   =     101;
  118.   IDM_MINUSBUB  =     102;
  119.   IDM_BUBBLE    =     103;
  120.   IDM_RANDOM    =     104;
  121.   IDM_START     =     105;
  122.   IDM_CHANGEVIEW =    106;
  123.  
  124. (* Fish Menu Items *)
  125.   IDM_SELECT    =     201;
  126.   IDM_INFO      =     202;
  127.  
  128.   FISHOPTION    =       1;
  129.  
  130.   IDM_DEFAULT   =     400;
  131.   IDM_FISH1     =     401;
  132.   IDM_FISH2     =     402;
  133.   IDM_FISH3     =     403;
  134.   IDM_FISH4     =     404;
  135.   IDM_FISH5     =     405;
  136.   IDM_FISH6     =     406;
  137.   IDM_FISH7     =     407;
  138.  
  139. (* debug options *)
  140.   IDM_DEBUG     =     300;
  141.   IDM_DESTROY   =     301;
  142.  
  143. (* Help Menu Items *)
  144.   IDM_ABOUT     =      901;
  145.   IDS_ABOUTA    =      902;
  146.  
  147. (* Timer Identifiers *)
  148.    FISHMOVE     =        1;
  149.    BUBBLEMOVE   =        2;
  150.    SETRANDOM    =        3;
  151.    STARMOVE     =        4;
  152.    WEEDMOVE     =        5;
  153.    CHESTMOVE    =        6;
  154.  
  155. (* other constants *)
  156.    FORWARDS     =       2;
  157.    BACKWARDS    =       1;
  158.    TURNING      =       0;
  159.  
  160.    FISHTIMER    =       40;
  161.    BUBBLETIMER  =       50;
  162.    RANDOMTIMER  =       1000;
  163.    STARTIMER    =       3000;
  164.    WEEDTIMER    =       4000;
  165.    CHESTTIMER   =       6000;
  166.  
  167.    BUBBLE_X_XTENT =     4;
  168.    BUBBLE_Y_XTENT =     4;
  169.  
  170.    MAXSTARS     =       4;
  171.    STARXPOS     =       200;
  172.    STARXXTENT   =       266;
  173.    STARXSIZE    =       66;
  174.    STARYSIZE    =       55;
  175.  
  176.    FLOORXSIZE   =       1000;
  177.    FLOORYSIZE   =       44;
  178.  
  179.    CLIENTREGION =       1;
  180.    FISHREGION   =       2;
  181.    STARREGION   =       3;
  182.    FLOORREGION  =       4;
  183.    CLIPREGION   =       5;
  184.    TANKREGION   =       6;
  185.    WEEDREGION   =       7;
  186.  
  187.    NORMAL       =       1;
  188.    FIT          =       2;
  189.  
  190.    WEEDXPOS     =       50;
  191.    MAXWEEDS     =       2;
  192.    WEEDXXTENT   =       266;
  193.    WEEDXSIZE    =       72;
  194.    WEEDYSIZE    =       72;
  195.  
  196.    TANKDEPTHDIFF =      50;
  197.  
  198.    SBHORZUNITS  =       10;
  199.    SBVERTUNITS  =       10;
  200.  
  201.    CHESTXPOS    =       425;
  202.    CHESTXXTENT  =       33;
  203.    CHESTYXTENT  =       28;
  204.  
  205.    SPECIAL_CHANGE =     0401H;
  206.    INIT_INSTANCES =     0402H;
  207.    RESTART        =     0403H;
  208.  
  209. TYPE
  210.     StarType    = RECORD
  211.                     hStar       : Windows.HBITMAP;
  212.                     StarPoints  : ARRAY[1..11] OF Windows.POINT;
  213.                     hStarRgn    : Windows.HRGN;
  214.                     hClipRgn    : Windows.HRGN;
  215.                   END;
  216.  
  217.     WeedType    = RECORD
  218.                     hWeed       : Windows.HBITMAP;
  219.                   END;
  220.  
  221.  
  222.     InvalidPtr = POINTER TO Invalids;
  223.     Invalids = RECORD
  224.                     top,left,bottom,right : INTEGER;
  225.                     NextInvalid : InvalidPtr;
  226.                END;
  227.  
  228.     Bubbles      = RECORD
  229.                      X,Y        : INTEGER;
  230.                      Speed      : CARDINAL;
  231.                    END;
  232.  
  233.  
  234. VAR
  235.   FishHere : INTEGER;
  236.   BubbleHead : ARRAY[1..10] OF Bubbles;
  237.   BubbleHere,BubbleMax : INTEGER;
  238.  
  239.   lpprocAbout,lpOpenDlg,lpLifeDlg,lpInfoDlg: Windows.FARPROC;
  240.  
  241.   hFISHF1A      : Windows.HBITMAP;
  242.   hFISHF1B      : Windows.HBITMAP;
  243.   hFISHF1C      : Windows.HBITMAP;
  244.   hFISHF1D      : Windows.HBITMAP;
  245.   hFISHB1A      : Windows.HBITMAP;
  246.   hFISHB1B      : Windows.HBITMAP;
  247.   hFISHB1C      : Windows.HBITMAP;
  248.   hFISHB1D      : Windows.HBITMAP;
  249.   hFISHT1       : Windows.HBITMAP;
  250.  
  251.   hFISHF2A      : Windows.HBITMAP;
  252.   hFISHF2B      : Windows.HBITMAP;
  253.   hFISHF2C      : Windows.HBITMAP;
  254.   hFISHF2D      : Windows.HBITMAP;
  255.   hFISHB2A      : Windows.HBITMAP;
  256.   hFISHB2B      : Windows.HBITMAP;
  257.   hFISHB2C      : Windows.HBITMAP;
  258.   hFISHB2D      : Windows.HBITMAP;
  259.   hFISHT2       : Windows.HBITMAP;
  260.  
  261.   hFISHF3A      : Windows.HBITMAP;
  262.   hFISHF3B      : Windows.HBITMAP;
  263.   hFISHF3C      : Windows.HBITMAP;
  264.   hFISHF3D      : Windows.HBITMAP;
  265.   hFISHB3A      : Windows.HBITMAP;
  266.   hFISHB3B      : Windows.HBITMAP;
  267.   hFISHB3C      : Windows.HBITMAP;
  268.   hFISHB3D      : Windows.HBITMAP;
  269.   hFISHT3       : Windows.HBITMAP;
  270.  
  271.   hFISHF4A      : Windows.HBITMAP;
  272.   hFISHF4B      : Windows.HBITMAP;
  273.   hFISHF4C      : Windows.HBITMAP;
  274.   hFISHF4D      : Windows.HBITMAP;
  275.   hFISHB4A      : Windows.HBITMAP;
  276.   hFISHB4B      : Windows.HBITMAP;
  277.   hFISHB4C      : Windows.HBITMAP;
  278.   hFISHB4D      : Windows.HBITMAP;
  279.   hFISHT4       : Windows.HBITMAP;
  280.  
  281.   hFISHF5A      : Windows.HBITMAP;
  282.   hFISHF5B      : Windows.HBITMAP;
  283.   hFISHF5C      : Windows.HBITMAP;
  284.   hFISHF5D      : Windows.HBITMAP;
  285.   hFISHB5A      : Windows.HBITMAP;
  286.   hFISHB5B      : Windows.HBITMAP;
  287.   hFISHB5C      : Windows.HBITMAP;
  288.   hFISHB5D      : Windows.HBITMAP;
  289.   hFISHT5       : Windows.HBITMAP;
  290.  
  291.   hFISHF6A      : Windows.HBITMAP;
  292.   hFISHF6B      : Windows.HBITMAP;
  293.   hFISHF6C      : Windows.HBITMAP;
  294.   hFISHF6D      : Windows.HBITMAP;
  295.   hFISHB6A      : Windows.HBITMAP;
  296.   hFISHB6B      : Windows.HBITMAP;
  297.   hFISHB6C      : Windows.HBITMAP;
  298.   hFISHB6D      : Windows.HBITMAP;
  299.   hFISHT6       : Windows.HBITMAP;
  300.  
  301.   hFISHF7A      : Windows.HBITMAP;
  302.   hFISHF7B      : Windows.HBITMAP;
  303.   hFISHF7C      : Windows.HBITMAP;
  304.   hFISHF7D      : Windows.HBITMAP;
  305.   hFISHB7A      : Windows.HBITMAP;
  306.   hFISHB7B      : Windows.HBITMAP;
  307.   hFISHB7C      : Windows.HBITMAP;
  308.   hFISHB7D      : Windows.HBITMAP;
  309.   hFISHT7       : Windows.HBITMAP;
  310.  
  311.   hBUBBLEbmap   : Windows.HBITMAP;
  312.   hBUBBLE1bmap  : Windows.HBITMAP;
  313.   hBUBBLE2bmap  : Windows.HBITMAP;
  314.   hBUBBLE3bmap  : Windows.HBITMAP;
  315.   hFLOORbmap    : Windows.HBITMAP;
  316.   hCHEST          : ARRAY [1..3] OF Windows.HBITMAP;
  317.  
  318.   hBUBBLES      : ARRAY[1..3] OF Windows.HBITMAP;
  319.   hSTARS        : ARRAY[1..MAXSTARS] OF StarType;
  320.   hWEEDS        : ARRAY[1..MAXWEEDS] OF WeedType;
  321.   hdc           : Windows.HDC;
  322.   hMemoryDC     : Windows.HDC;
  323.   Bitmap        : Windows.BITMAP;
  324.   hOldbmap      : Windows.HBITMAP;
  325.   LPBitmap      : Windows.LPBITMAP;
  326.   TempRect      : Windows.RECT;
  327.   XYRect,OldXYRect : Windows.RECT;
  328.  
  329.   staron,bubbleon,done,randomset      : BOOLEAN;
  330.   bubblewason,starwason,randomwasset  : BOOLEAN;
  331.   timerid,randomy                     : INTEGER;
  332.   TankWidth,TankDepth                 : INTEGER;
  333.   TempStr                             : ARRAY[0..15] OF CHAR;
  334.  
  335.   starypos, staryxtent,
  336.   floorypos, weedypos,
  337.   chestypos, weedyxtent,
  338.   weed, prevweed                      : INTEGER;
  339.  
  340.   fishxpos                            : INTEGER;
  341.   bubbleypos,bubble                   : INTEGER;
  342.  
  343.   star, prevstar,
  344.   chest                               : INTEGER;
  345.  
  346.   WindowOrg                           : LONGCARD;
  347.  
  348.   SbXPos,SbYPos                       : INTEGER;
  349.  
  350.   SbXInc,SbYInc,Temp1,Temp2           : INTEGER;
  351.  
  352.   movement                            : INTEGER;
  353.   maxheight                           : INTEGER;
  354.  
  355.   hRgna, hTankRgn                     : Windows.HRGN;
  356.   hStarRgn, hFishRgn,
  357.   hFloorRgn, hClientRgn,
  358.   hUnionRgn, hClipRgn                 : Windows.HRGN;
  359.  
  360.   ClipRgnType,ViewType,OldMapMode     : INTEGER;
  361.  
  362.   Dextent                             : LONGINT;
  363.  
  364.   hOldBrush, hBrush                   : Windows.HBRUSH;
  365.  
  366.   hAccTable                           : Windows.HANDLE;
  367.  
  368.  
  369. PROCEDURE MessagePaint( hWnd    : Windows.HWND;
  370.                         hdc     : Windows.HDC;
  371.                         RCPaint : Windows.RECT);
  372. VAR FishHere : INTEGER;
  373. BEGIN
  374.  
  375.     IF ClipRgnType = 99 THEN   (* special case *)
  376.        IF Windows.BitBlt(hdc,0,0,1,1,hMemoryDC,0,0,
  377.                          Windows.BLACKNESS) = 0 THEN END
  378.     END;
  379.  
  380.     IF (ClipRgnType = CLIENTREGION) OR
  381.        (ClipRgnType = FISHREGION) OR
  382.        (ClipRgnType = TANKREGION) OR
  383.        (ClipRgnType = CLIPREGION) THEN
  384.        FishHere := 1;
  385.              WHILE (FishHere <= FishMax) DO
  386.               IF FishHead[FishHere].status THEN
  387.                  hOldbmap := Windows.SelectObject(hMemoryDC, FishHead[FishHere].bmap[FishHead[FishHere].direction,
  388.                                                   FishHead[FishHere].bmapno]);
  389.                  IF Windows.BitBlt(hdc,FishHead[FishHere].xpos,FishHead[FishHere].ypos,
  390.                                    FishHead[FishHere].xextent,FishHead[FishHere].yextent,
  391.                                    hMemoryDC,0,0,Windows.SRCPAINT) # 0 THEN END;
  392.                  InstanceHead := FishHead[FishHere].Other;
  393.                  WHILE InstanceHead # NIL DO
  394.                      hOldbmap := Windows.SelectObject(hMemoryDC, FishHead[FishHere].bmap[FishHead[FishHere].direction,
  395.                                                       InstanceHead^.bmapno]);
  396.                      IF Windows.BitBlt(hdc,InstanceHead^.xpos,InstanceHead^.ypos,
  397.                                        FishHead[FishHere].xextent,FishHead[FishHere].yextent,hMemoryDC,0,0,
  398.                                        Windows.SRCPAINT) # 0 THEN END;
  399.                      InstanceHead := InstanceHead^.NextInstance
  400.                  END
  401.               END;
  402.               FishHere := FishHere+1;
  403.            END; (* DO *)
  404.         FishHere := 1;
  405.      END;
  406.  
  407.     IF (ClipRgnType = CLIENTREGION) OR
  408.        (ClipRgnType = TANKREGION) OR
  409.        (ClipRgnType = FLOORREGION) OR
  410.        (ClipRgnType = CLIPREGION) THEN
  411.        IF ClipRgnType = CLIPREGION THEN
  412.           IF Windows.SelectClipRgn(hdc,hFloorRgn) = 0 THEN END;
  413.           hOldbmap    := Windows.SelectObject(hMemoryDC,hFLOORbmap);
  414.           IF Windows.BitBlt(hdc,0,floorypos,FLOORXSIZE,FLOORYSIZE,hMemoryDC,0,0,Windows.SRCCOPY) # 0 THEN END;
  415.           IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = 0 THEN END
  416.        ELSE
  417.           hOldbmap    := Windows.SelectObject(hMemoryDC,hFLOORbmap);
  418.           IF Windows.BitBlt(hdc,0,floorypos,FLOORXSIZE,FLOORYSIZE,hMemoryDC,0,0,Windows.SRCCOPY) # 0 THEN END;
  419.        END
  420.     ELSIF
  421.        (Windows.RectInRegion(hFloorRgn,RCPaint) # 0) THEN
  422.  
  423.        IF Windows.SelectClipRgn(hdc,hFloorRgn) = 0 THEN END;
  424.        hOldbmap    := Windows.SelectObject(hMemoryDC,hFLOORbmap);
  425.        IF Windows.BitBlt(hdc,0,floorypos,FLOORXSIZE,FLOORYSIZE,hMemoryDC,0,0,Windows.SRCCOPY) # 0 THEN END;
  426.        CASE ClipRgnType OF
  427.          | CLIPREGION:
  428.            IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = 0 THEN END;
  429.          | STARREGION:
  430.            IF Windows.SelectClipRgn(hdc,hSTARS[star].hStarRgn) = 0 THEN END;
  431.          | WEEDREGION:
  432.            IF Windows.SelectClipRgn(hdc,hFloorRgn) = 0 THEN END;
  433.        END;
  434.  
  435.     END;
  436.  
  437.     IF (ClipRgnType = CLIENTREGION) OR
  438.        (ClipRgnType = STARREGION) OR
  439.        (ClipRgnType = CLIPREGION) OR
  440.        (ClipRgnType = TANKREGION) THEN (* if these  are changed then change case *)
  441.  
  442.        IF Windows.SelectClipRgn(hdc,hSTARS[star].hStarRgn) = 0 THEN END;
  443.        hOldbmap := Windows.SelectObject(hMemoryDC,hSTARS[star].hStar);
  444.        IF Windows.BitBlt(hdc,STARXPOS,starypos,STARXSIZE,STARYSIZE,hMemoryDC,0,0,Windows.SRCPAINT) # 0 THEN END;
  445.  
  446.        CASE ClipRgnType OF
  447.          | CLIENTREGION:
  448.            IF Windows.SelectClipRgn(hdc,hClientRgn) = 0 THEN END;
  449.          | TANKREGION:
  450.            IF Windows.SelectClipRgn(hdc,hTankRgn) = 0 THEN END;
  451.          | CLIPREGION:
  452.            IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = 0 THEN END;
  453.        END;
  454.  
  455.     END;
  456.  
  457.     IF (ClipRgnType = CLIENTREGION) OR
  458.        (ClipRgnType = WEEDREGION) OR
  459.        (ClipRgnType = CLIPREGION) OR
  460.        (ClipRgnType = TANKREGION) THEN (* if these  are changed then change case *)
  461.  
  462.        IF Windows.SelectClipRgn(hdc,hFloorRgn) = 0 THEN END;
  463.        hOldbmap := Windows.SelectObject(hMemoryDC,hWEEDS[weed].hWeed);
  464.        IF Windows.BitBlt(hdc,WEEDXPOS,weedypos,WEEDXSIZE,WEEDYSIZE,hMemoryDC,0,0,Windows.SRCPAINT) # 0 THEN END;
  465.  
  466.        CASE ClipRgnType OF
  467.          | CLIENTREGION:
  468.            IF Windows.SelectClipRgn(hdc,hClientRgn) = 0 THEN END;
  469.          | TANKREGION:
  470.            IF Windows.SelectClipRgn(hdc,hTankRgn) = 0 THEN END;
  471.          | CLIPREGION:
  472.            IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = 0 THEN END;
  473.        END;
  474.  
  475.     END;
  476.  
  477.  
  478. END MessagePaint;
  479.  
  480. PROCEDURE Increase( VAR X : INTEGER);
  481. BEGIN
  482.     IF X < 0 THEN DEC(X) END;
  483.     IF X > 0 THEN INC(X) END;
  484. END Increase;
  485.  
  486. PROCEDURE ReDrawAll(hWnd     : Windows.HWND;
  487.                     ClipType : INTEGER );
  488. BEGIN
  489.     ClipRgnType := TANKREGION;
  490.     IF Windows.SelectClipRgn(hdc,hTankRgn) = 0 THEN END;
  491.  
  492.     Windows.InvalidateRgn(hWnd,hTankRgn,1);
  493.     Windows.UpdateWindow(hWnd);
  494.  
  495.     CASE ClipType OF
  496.  
  497.          | CLIPREGION:
  498.            ClipRgnType := CLIPREGION;
  499.            IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = 0 THEN END;
  500.  
  501.          | STARREGION:
  502.            ClipRgnType := STARREGION;
  503.            IF Windows.SelectClipRgn(hdc,hSTARS[star].hStarRgn) = 0 THEN END;
  504.  
  505.          | FLOORREGION:
  506.            ClipRgnType := FLOORREGION;
  507.            IF Windows.SelectClipRgn(hdc,hFloorRgn) = 0 THEN END;
  508.  
  509.          | CLIENTREGION:
  510.            ClipRgnType := CLIENTREGION;
  511.            IF Windows.SelectClipRgn(hdc,hClientRgn) = 0 THEN END;
  512.     END;
  513. END ReDrawAll;
  514.  
  515.  
  516. PROCEDURE CreateFishNode(Name           : NameType;
  517.                          FishHere       : INTEGER ;
  518.                          stat           : BOOLEAN;
  519.                          bmap1, bmap2,
  520.                          bmap3, bmap4,
  521.                          bmap5, bmap6,
  522.                          bmap7, bmap8,
  523.                          bmap9          : Windows.HBITMAP;
  524.                          xpos,ypos      : INTEGER;
  525.                          xextent,
  526.                          yextent,
  527.                          basespeed      : INTEGER;
  528.                          direction,
  529.                          timerid        : INTEGER );
  530. BEGIN
  531.   FishHead[FishHere].name := Name;
  532.   FishHead[FishHere].status := stat;
  533.   IF direction = BACKWARDS THEN
  534.       FishHead[FishHere].bmap[BACKWARDS,1] := bmap1;
  535.       FishHead[FishHere].bmap[BACKWARDS,2] := bmap2;
  536.       FishHead[FishHere].bmap[BACKWARDS,3] := bmap3;
  537.       FishHead[FishHere].bmap[BACKWARDS,4] := bmap4;
  538.       FishHead[FishHere].bmap[FORWARDS,1] := bmap5;
  539.       FishHead[FishHere].bmap[FORWARDS,2] := bmap6;
  540.       FishHead[FishHere].bmap[FORWARDS,3] := bmap7;
  541.       FishHead[FishHere].bmap[FORWARDS,4] := bmap8;
  542.   ELSE
  543.       FishHead[FishHere].bmap[BACKWARDS,1] := bmap5;
  544.       FishHead[FishHere].bmap[BACKWARDS,2] := bmap6;
  545.       FishHead[FishHere].bmap[BACKWARDS,3] := bmap7;
  546.       FishHead[FishHere].bmap[BACKWARDS,4] := bmap8;
  547.       FishHead[FishHere].bmap[FORWARDS,1] := bmap1;
  548.       FishHead[FishHere].bmap[FORWARDS,2] := bmap2;
  549.       FishHead[FishHere].bmap[FORWARDS,3] := bmap3;
  550.       FishHead[FishHere].bmap[FORWARDS,4] := bmap4;
  551.   END;
  552.   FishHead[FishHere].Other := NIL;
  553.   FishHead[FishHere].Instances := 0;
  554.   FishHead[FishHere].turnbmap := bmap9;
  555.   FishHead[FishHere].bmapno := 1;
  556.   FishHead[FishHere].DialogFrame := 1;
  557.   FishHead[FishHere].xpos := xpos;
  558.   FishHead[FishHere].ypos := ypos;
  559.   FishHead[FishHere].xextent := xextent;
  560.   FishHead[FishHere].yextent := yextent;
  561.  
  562.   IF direction = FORWARDS THEN
  563.     FishHead[FishHere].speedx := basespeed;
  564.   ELSE
  565.     FishHead[FishHere].speedx := -basespeed;
  566.   END;
  567.  
  568.   FishHead[FishHere].pspeedx := FishHead[FishHere].speedx;
  569.   FishHead[FishHere].speedy := 0;
  570.   FishHead[FishHere].pspeedy := 0;
  571.   FishHead[FishHere].basespeed := basespeed;
  572.   FishHead[FishHere].direction := direction;
  573.   FishHead[FishHere].TimerId := timerid;
  574.  
  575. END CreateFishNode;
  576.  
  577. PROCEDURE SetRectInvalid( hWnd          : Windows.HWND;
  578.                           top, left,
  579.                           bottom, right :INTEGER);
  580.  
  581. VAR InvalidRect : Windows.RECT;
  582.  
  583. BEGIN
  584.  
  585.     InvalidRect.top := top;
  586.     InvalidRect.right := right;
  587.     InvalidRect.bottom := bottom;
  588.     InvalidRect.left := left;
  589.     Windows.InvalidateRect(hWnd,InvalidRect,1);
  590.  
  591. END SetRectInvalid;
  592.  
  593.  
  594. PROCEDURE  SetUpBubbles;
  595. VAR i : INTEGER;
  596. BEGIN
  597.   BubbleMax := 4;
  598.  
  599.   BubbleHead[1].X := RANDOM(XYRect.right);
  600.   BubbleHead[1].Y := RANDOM(XYRect.bottom DIV 3);
  601.   BubbleHead[1].Speed := RANDOM(3) + 4;
  602.  
  603.   BubbleHead[2].X := RANDOM(XYRect.right);
  604.   BubbleHead[2].Y := RANDOM(XYRect.bottom DIV 3)  + (CARDINAL(XYRect.bottom) DIV 3);
  605.   BubbleHead[2].Speed := RANDOM(3) + 4;
  606.  
  607.   BubbleHead[3].X := RANDOM(XYRect.right);
  608.   BubbleHead[3].Y := RANDOM(XYRect.bottom DIV 3)  + (CARDINAL(XYRect.bottom) DIV 3);
  609.   BubbleHead[3].Speed := RANDOM(3) + 4;
  610.  
  611.   BubbleHead[4].X := RANDOM(XYRect.right);
  612.   BubbleHead[4].Y := RANDOM(XYRect.bottom DIV 3) +(2* (CARDINAL(XYRect.bottom) DIV 3));
  613.   BubbleHead[4].Speed := RANDOM(3) + 4;
  614.  
  615. END SetUpBubbles;
  616.  
  617. PROCEDURE ResizeStarParams(hWnd : Windows.HWND) : BOOLEAN;
  618.  
  619. VAR Xorg,Yorg,i         : INTEGER;
  620.     Origin              : LONGCARD;
  621.  
  622. BEGIN
  623.  
  624.     Origin := Windows.GetWindowOrg(hdc);
  625.     Xorg := INTEGER(Windows.LOWORD(Origin));
  626.     Yorg := INTEGER(Windows.HIWORD(Origin));
  627.  
  628.     starypos := floorypos - 47;
  629.     staryxtent := floorypos - 47 + STARYSIZE;
  630.     hSTARS[1].StarPoints[1].x := STARXPOS + 52; (* these map the points of the perimiter of the star *)
  631.     hSTARS[1].StarPoints[1].y := starypos + 2;
  632.     hSTARS[1].StarPoints[2].x := STARXPOS + 43;
  633.     hSTARS[1].StarPoints[2].y := starypos + 23;
  634.     hSTARS[1].StarPoints[3].x := STARXPOS + 65;
  635.     hSTARS[1].StarPoints[3].y := starypos + 35;
  636.     hSTARS[1].StarPoints[4].x := STARXPOS + 38;
  637.     hSTARS[1].StarPoints[4].y := starypos + 36;
  638.     hSTARS[1].StarPoints[5].x := STARXPOS + 30;
  639.     hSTARS[1].StarPoints[5].y := starypos + 53;
  640.     hSTARS[1].StarPoints[6].x := STARXPOS + 24;
  641.     hSTARS[1].StarPoints[6].y := starypos + 36;
  642.     hSTARS[1].StarPoints[7].x := STARXPOS + 3;
  643.     hSTARS[1].StarPoints[7].y := starypos + 39;
  644.     hSTARS[1].StarPoints[8].x := STARXPOS + 21;
  645.     hSTARS[1].StarPoints[8].y := starypos + 25;
  646.     hSTARS[1].StarPoints[9].x := STARXPOS + 9;
  647.     hSTARS[1].StarPoints[9].y := starypos + 8;
  648.     hSTARS[1].StarPoints[10].x := STARXPOS + 31;
  649.     hSTARS[1].StarPoints[10].y := starypos + 16;
  650.     hSTARS[1].StarPoints[11].x := STARXPOS + 52;
  651.     hSTARS[1].StarPoints[11].y := starypos + 2;
  652.  
  653.     hSTARS[2].StarPoints[1].x := STARXPOS + 11;
  654.     hSTARS[2].StarPoints[1].y := starypos + 2;
  655.     hSTARS[2].StarPoints[2].x := STARXPOS + 33;
  656.     hSTARS[2].StarPoints[2].y := starypos + 15;
  657.     hSTARS[2].StarPoints[3].x := STARXPOS + 55;
  658.     hSTARS[2].StarPoints[3].y := starypos + 7 ;
  659.     hSTARS[2].StarPoints[4].x := STARXPOS + 43;
  660.     hSTARS[2].StarPoints[4].y := starypos + 25;
  661.     hSTARS[2].StarPoints[5].x := STARXPOS + 62;
  662.     hSTARS[2].StarPoints[5].y := starypos + 41;
  663.     hSTARS[2].StarPoints[6].x := STARXPOS + 40;
  664.     hSTARS[2].StarPoints[6].y := starypos + 36;
  665.     hSTARS[2].StarPoints[7].x := STARXPOS + 34;
  666.     hSTARS[2].StarPoints[7].y := starypos + 52;
  667.     hSTARS[2].StarPoints[8].x := STARXPOS + 25;
  668.     hSTARS[2].StarPoints[8].y := starypos + 34;
  669.     hSTARS[2].StarPoints[9].x := STARXPOS + 0;
  670.     hSTARS[2].StarPoints[9].y := starypos + 36;
  671.     hSTARS[2].StarPoints[10].x := STARXPOS + 21;
  672.     hSTARS[2].StarPoints[10].y := starypos + 21;
  673.     hSTARS[2].StarPoints[11].x := STARXPOS + 11;
  674.     hSTARS[2].StarPoints[11].y := starypos + 2;
  675.  
  676.     hSTARS[3].StarPoints[1].x := STARXPOS + 31;
  677.     hSTARS[3].StarPoints[1].y := starypos + 15;
  678.     hSTARS[3].StarPoints[2].x := STARXPOS + 52;
  679.     hSTARS[3].StarPoints[2].y := starypos + 0 ;
  680.     hSTARS[3].StarPoints[3].x := STARXPOS + 43;
  681.     hSTARS[3].StarPoints[3].y := starypos + 21;
  682.     hSTARS[3].StarPoints[4].x := STARXPOS + 63;
  683.     hSTARS[3].StarPoints[4].y := starypos + 33;
  684.     hSTARS[3].StarPoints[5].x := STARXPOS + 39;
  685.     hSTARS[3].StarPoints[5].y := starypos + 33;
  686.     hSTARS[3].StarPoints[6].x := STARXPOS + 29;
  687.     hSTARS[3].StarPoints[6].y := starypos + 50;
  688.     hSTARS[3].StarPoints[7].x := STARXPOS + 23;
  689.     hSTARS[3].StarPoints[7].y := starypos + 34;
  690.     hSTARS[3].StarPoints[8].x := STARXPOS + 0 ;
  691.     hSTARS[3].StarPoints[8].y := starypos + 38;
  692.     hSTARS[3].StarPoints[9].x := STARXPOS + 20;
  693.     hSTARS[3].StarPoints[9].y := starypos + 25;
  694.     hSTARS[3].StarPoints[10].x := STARXPOS + 8 ;
  695.     hSTARS[3].StarPoints[10].y := starypos + 5 ;
  696.     hSTARS[3].StarPoints[11].x := STARXPOS + 31;
  697.     hSTARS[3].StarPoints[11].y := starypos + 15;
  698.  
  699.     hSTARS[4].StarPoints[1].x := STARXPOS + 15;
  700.     hSTARS[4].StarPoints[1].y := starypos + 3;
  701.     hSTARS[4].StarPoints[2].x := STARXPOS + 36;
  702.     hSTARS[4].StarPoints[2].y := starypos + 17;
  703.     hSTARS[4].StarPoints[3].x := STARXPOS + 57;
  704.     hSTARS[4].StarPoints[3].y := starypos + 7 ;
  705.     hSTARS[4].StarPoints[4].x := STARXPOS + 46;
  706.     hSTARS[4].StarPoints[4].y := starypos + 26;
  707.     hSTARS[4].StarPoints[5].x := STARXPOS + 64;
  708.     hSTARS[4].StarPoints[5].y := starypos + 40;
  709.     hSTARS[4].StarPoints[6].x := STARXPOS + 43;
  710.     hSTARS[4].StarPoints[6].y := starypos + 36;
  711.     hSTARS[4].StarPoints[7].x := STARXPOS + 37;
  712.     hSTARS[4].StarPoints[7].y := starypos + 54;
  713.     hSTARS[4].StarPoints[8].x := STARXPOS + 28;
  714.     hSTARS[4].StarPoints[8].y := starypos + 35;
  715.     hSTARS[4].StarPoints[9].x := STARXPOS + 3;
  716.     hSTARS[4].StarPoints[9].y := starypos + 35;
  717.     hSTARS[4].StarPoints[10].x := STARXPOS + 25;
  718.     hSTARS[4].StarPoints[10].y := starypos + 24;
  719.     hSTARS[4].StarPoints[11].x := STARXPOS + 15;
  720.     hSTARS[4].StarPoints[11].y := starypos + 3;
  721.  
  722.     FOR i := 1 TO 4 DO (* create regions which contain exactly each star *)
  723.         IF Windows.DeleteObject(hSTARS[i].hStarRgn) = 0 THEN END;
  724.  
  725.         hSTARS[i].hStarRgn := Windows.CreatePolygonRgn(hSTARS[i].StarPoints[1],11,Windows.WINDING);
  726.  
  727.         IF hSTARS[i].hStarRgn = 0 THEN
  728.            RETURN(ApplFish.ResourcesLow(hWnd))
  729.         END
  730.  
  731.     END;
  732.  
  733.     IF Windows.DeleteObject(hClientRgn) = 0 THEN END;
  734.     hClientRgn := Windows.CreateRectRgn(0,0,TankWidth,TankDepth);
  735.     IF hClientRgn = 0 THEN
  736.        RETURN(ApplFish.ResourcesLow(hWnd))
  737.     END;
  738.  
  739.     (* create clip regions *)
  740.  
  741.     IF Windows.CombineRgn(hFishRgn,hClientRgn,hFloorRgn,Windows.RGN_DIFF) = Windows.ERROR THEN
  742.            RETURN(ApplFish.ResourcesLow(hWnd))
  743.     END;
  744.  
  745.     IF Windows.CombineRgn(hSTARS[1].hClipRgn,hFishRgn,hSTARS[1].hStarRgn,Windows.RGN_DIFF) = Windows.ERROR THEN
  746.            RETURN(ApplFish.ResourcesLow(hWnd))
  747.     END;
  748.     IF Windows.CombineRgn(hSTARS[2].hClipRgn,hFishRgn,hSTARS[2].hStarRgn,Windows.RGN_DIFF) = Windows.ERROR THEN
  749.            RETURN(ApplFish.ResourcesLow(hWnd))
  750.     END;
  751.     IF Windows.CombineRgn(hSTARS[3].hClipRgn,hFishRgn,hSTARS[3].hStarRgn,Windows.RGN_DIFF) = Windows.ERROR THEN
  752.            RETURN(ApplFish.ResourcesLow(hWnd))
  753.     END;
  754.     IF Windows.CombineRgn(hSTARS[4].hClipRgn,hFishRgn,hSTARS[4].hStarRgn,Windows.RGN_DIFF) = Windows.ERROR THEN
  755.            RETURN(ApplFish.ResourcesLow(hWnd))
  756.     END;
  757.  
  758.     IF Windows.DeleteObject(hFishRgn) # 0 THEN END;
  759.     RETURN FALSE
  760.  
  761. END ResizeStarParams;
  762.  
  763. PROCEDURE ReCalcFloorRegion(hWnd : Windows.HWND) : BOOLEAN;
  764.  
  765. VAR FloorPoints : ARRAY[1..70] OF Windows.POINT;
  766.  
  767. BEGIN
  768.  
  769.     FloorPoints[1].x := 0;
  770.     FloorPoints[1].y := floorypos + 29;
  771.     FloorPoints[2].x := 5;
  772.     FloorPoints[2].y := floorypos + 13;
  773.     FloorPoints[3].x := 12;
  774.     FloorPoints[3].y := floorypos + 12;
  775.     FloorPoints[4].x := 15;
  776.     FloorPoints[4].y := floorypos + 7;
  777.     FloorPoints[5].x := 22;
  778.     FloorPoints[5].y := floorypos + 6;
  779.     FloorPoints[6].x := 23;
  780.     FloorPoints[6].y := floorypos + 12;
  781.     FloorPoints[7].x := 35;
  782.     FloorPoints[7].y := floorypos + 6;
  783.     FloorPoints[8].x := 53;
  784.     FloorPoints[8].y := floorypos + 0;
  785.  
  786.     weedypos := floorypos - WEEDYSIZE+1;
  787.     weedyxtent := floorypos;
  788.     FloorPoints[1+8].x := WEEDXPOS + 5;
  789.     FloorPoints[1+8].y := weedypos + 71;
  790.     FloorPoints[2+8].x := WEEDXPOS + 9;
  791.     FloorPoints[2+8].y := weedypos + 58;
  792.     FloorPoints[3+8].x := WEEDXPOS + 1;
  793.     FloorPoints[3+8].y := weedypos + 45;
  794.     FloorPoints[4+8].x := WEEDXPOS + 7;
  795.     FloorPoints[4+8].y := weedypos + 15;
  796.     FloorPoints[5+8].x := WEEDXPOS + 11;
  797.     FloorPoints[5+8].y := weedypos + 8;
  798.     FloorPoints[6+8].x := WEEDXPOS + 31;
  799.     FloorPoints[6+8].y := weedypos + 41;
  800.     FloorPoints[7+8].x := WEEDXPOS + 34;
  801.     FloorPoints[7+8].y := weedypos + 51;
  802.     FloorPoints[8+8].x := WEEDXPOS + 44;
  803.     FloorPoints[8+8].y := weedypos + 29;
  804.     FloorPoints[9+8].x := WEEDXPOS + 46;
  805.     FloorPoints[9+8].y := weedypos + 13;
  806.     FloorPoints[10+8].x := WEEDXPOS + 55;
  807.     FloorPoints[10+8].y := weedypos + 0;
  808.     FloorPoints[11+8].x := WEEDXPOS + 60;
  809.     FloorPoints[11+8].y := weedypos + 1;
  810.     FloorPoints[12+8].x := WEEDXPOS + 63;
  811.     FloorPoints[12+8].y := weedypos + 11;
  812.     FloorPoints[13+8].x := WEEDXPOS + 58;
  813.     FloorPoints[13+8].y := weedypos + 24;
  814.     FloorPoints[14+8].x := WEEDXPOS + 58;
  815.     FloorPoints[14+8].y := weedypos + 48;
  816.     FloorPoints[15+8].x := WEEDXPOS + 64;
  817.     FloorPoints[15+8].y := weedypos + 56;
  818.     FloorPoints[16+8].x := WEEDXPOS + 59;
  819.     FloorPoints[16+8].y := weedypos + 71;
  820.  
  821.     FloorPoints[9+16].x := 112;
  822.     FloorPoints[9+16].y := floorypos + 0;
  823.     FloorPoints[10+16].x := 116;
  824.     FloorPoints[10+16].y := floorypos + 5;
  825.  
  826.     FloorPoints[11+16].x := 135;
  827.     FloorPoints[11+16].y := floorypos + 3;
  828.     FloorPoints[12+16].x := 143;
  829.     FloorPoints[12+16].y := floorypos + 7;
  830.     FloorPoints[13+16].x := 161;
  831.     FloorPoints[13+16].y := floorypos + 0;
  832.     FloorPoints[14+16].x := 168;
  833.     FloorPoints[14+16].y := floorypos + 0;
  834.     FloorPoints[15+16].x := 190;
  835.     FloorPoints[15+16].y := floorypos + 5;
  836.     FloorPoints[16+16].x := 215;
  837.     FloorPoints[16+16].y := floorypos + 5;
  838.     FloorPoints[17+16].x := 223;
  839.     FloorPoints[17+16].y := floorypos + 1;
  840.     FloorPoints[18+16].x := 246;
  841.     FloorPoints[18+16].y := floorypos + 0;
  842.     FloorPoints[19+16].x := 258;
  843.     FloorPoints[19+16].y := floorypos + 6;
  844.     FloorPoints[20+16].x := 271;
  845.     FloorPoints[20+16].y := floorypos + 6;
  846.     FloorPoints[21+16].x := 293;
  847.     FloorPoints[21+16].y := floorypos + 16;
  848.     FloorPoints[22+16].x := 312;
  849.     FloorPoints[22+16].y := floorypos + 17;
  850.     FloorPoints[23+16].x := 321;
  851.     FloorPoints[23+16].y := floorypos + 22;
  852.     FloorPoints[24+16].x := 324;
  853.     FloorPoints[24+16].y := floorypos + 29;
  854.     FloorPoints[25+16].x := 336;
  855.     FloorPoints[25+16].y := floorypos + 31;
  856.     FloorPoints[26+16].x := 342;
  857.     FloorPoints[26+16].y := floorypos + 23;
  858.     FloorPoints[27+16].x := 347;
  859.     FloorPoints[27+16].y := floorypos + 21;
  860.     FloorPoints[28+16].x := 347;
  861.     FloorPoints[28+16].y := floorypos + 13;
  862.     FloorPoints[29+16].x := 352;
  863.     FloorPoints[29+16].y := floorypos + 8;
  864.  
  865.     FloorPoints[30+16].x := 363;
  866.     FloorPoints[30+16].y := floorypos + 23;
  867.     FloorPoints[31+16].x := 384;
  868.     FloorPoints[31+16].y := floorypos + 22;
  869.     FloorPoints[32+16].x := 391;
  870.     FloorPoints[32+16].y := floorypos + 3;
  871.     FloorPoints[33+16].x := 398;
  872.     FloorPoints[33+16].y := floorypos + 0;
  873.     FloorPoints[34+16].x := 404;
  874.     FloorPoints[34+16].y := floorypos + 10;
  875.     FloorPoints[35+16].x := 403;
  876.     FloorPoints[35+16].y := floorypos + 18;
  877.     FloorPoints[36+16].x := 413;
  878.     FloorPoints[36+16].y := floorypos + 19;
  879.     FloorPoints[37+16].x := 429;
  880.     FloorPoints[37+16].y := floorypos + 2;
  881.     FloorPoints[38+16].x := 469;
  882.     FloorPoints[38+16].y := floorypos + 4;
  883.     FloorPoints[39+16].x := 492;
  884.     FloorPoints[39+16].y := floorypos + 2;
  885.     FloorPoints[40+16].x := 511;
  886.     FloorPoints[40+16].y := floorypos + 3;
  887.     FloorPoints[41+16].x := 515;
  888.     FloorPoints[41+16].y := floorypos + 7;
  889.     FloorPoints[42+16].x := 533;
  890.     FloorPoints[42+16].y := floorypos + 2;
  891.     FloorPoints[43+16].x := 541;
  892.     FloorPoints[43+16].y := floorypos + 3;
  893.     FloorPoints[44+16].x := 576;
  894.     FloorPoints[44+16].y := floorypos + 43;
  895.     FloorPoints[45+16].x := 590;
  896.     FloorPoints[45+16].y := floorypos + 43;
  897.     FloorPoints[46+16].x := 596;
  898.     FloorPoints[46+16].y := floorypos + 29;
  899.     FloorPoints[47+16].x := 602;
  900.     FloorPoints[47+16].y := floorypos + 29;
  901.     FloorPoints[48+16].x := 611;
  902.     FloorPoints[48+16].y := floorypos + 45;
  903.     FloorPoints[49+16].x := 627;
  904.     FloorPoints[49+16].y := floorypos + 21;
  905.     FloorPoints[50+16].x := 646;
  906.     FloorPoints[50+16].y := floorypos + 13;
  907.     FloorPoints[51+16].x := 646;
  908.     FloorPoints[51+16].y := floorypos + 45;
  909.     FloorPoints[52+16].x := 0;
  910.     FloorPoints[52+16].y := floorypos + 45;
  911.     FloorPoints[53+16].x := 0;
  912.     FloorPoints[53+16].y := floorypos + 29;
  913.  
  914.     hFloorRgn := Windows.CreatePolygonRgn(FloorPoints[1],69,Windows.WINDING);
  915.     IF hFloorRgn = 0 THEN
  916.            RETURN(ApplFish.ResourcesLow(hWnd))
  917.     END;
  918.     RETURN FALSE
  919.  
  920. END ReCalcFloorRegion;
  921.  
  922. PROCEDURE ReCalcRegions(hWnd : Windows.HWND) : BOOLEAN; (* Called when the Window Org is changed by scroll bar *)
  923. VAR Xorg,Yorg,i : INTEGER;
  924.     Origin      : LONGCARD;
  925. BEGIN
  926.  
  927.     Origin := Windows.GetWindowOrg(hdc);
  928.     Xorg := INTEGER(Windows.LOWORD(Origin));
  929.     Yorg := INTEGER(Windows.HIWORD(Origin));
  930.  
  931.     FOR i := 1 TO 4 DO
  932.         IF Windows.DeleteObject(hSTARS[i].hStarRgn) = 0 THEN END;
  933.         hSTARS[i].hStarRgn := Windows.CreatePolygonRgn(hSTARS[i].StarPoints[1],11,Windows.WINDING);
  934.         IF hSTARS[i].hStarRgn = 0 THEN
  935.            RETURN(ApplFish.ResourcesLow(hWnd))
  936.         END
  937.     END;
  938.  
  939.     IF Windows.OffsetRgn(hSTARS[1].hStarRgn,-SbXInc,-SbYInc) = 0 THEN END;
  940.     IF Windows.OffsetRgn(hSTARS[2].hStarRgn,-SbXInc,-SbYInc) = 0 THEN END;
  941.     IF Windows.OffsetRgn(hSTARS[3].hStarRgn,-SbXInc,-SbYInc) = 0 THEN END;
  942.     IF Windows.OffsetRgn(hSTARS[4].hStarRgn,-SbXInc,-SbYInc) = 0 THEN END;
  943.  
  944.     IF Windows.DeleteObject(hFloorRgn) = 0 THEN END;
  945.     IF ReCalcFloorRegion(hWnd) THEN (* Resource problem *)
  946.        RETURN (FALSE)
  947.     END;
  948.     IF Windows.OffsetRgn(hFloorRgn,-SbXInc,-SbYInc) = 0 THEN END;
  949.  
  950.     hFishRgn := Windows.CreateRectRgnIndirect(XYRect); (* Needs to be created just once for combine rgn *)
  951.     IF hFishRgn = 0 THEN
  952.        RETURN(ApplFish.ResourcesLow(hWnd))
  953.     END;
  954.  
  955.     IF Windows.CombineRgn(hFishRgn,hClientRgn,hFloorRgn,Windows.RGN_DIFF) = Windows.ERROR THEN
  956.        RETURN(ApplFish.ResourcesLow(hWnd))
  957.     END;
  958.  
  959.     FOR i := 1 TO MAXSTARS DO
  960.         IF Windows.CombineRgn(hSTARS[i].hClipRgn,hFishRgn,hSTARS[i].hStarRgn,Windows.RGN_DIFF) = Windows.ERROR THEN
  961.                RETURN(ApplFish.ResourcesLow(hWnd))
  962.         END
  963.     END;
  964.  
  965.     IF Windows.DeleteObject(hFishRgn) # 0 THEN END;
  966.  
  967.     RETURN FALSE
  968. END ReCalcRegions;
  969.  
  970. PROCEDURE QuickDeleteRgns(hWnd  : Windows.HWND);
  971. VAR i : INTEGER;
  972. BEGIN
  973.        FOR i := 1 TO MAXSTARS DO
  974.            IF Windows.DeleteObject(hSTARS[i].hStarRgn) = 0 THEN END;
  975.            IF Windows.DeleteObject(hSTARS[i].hStar) # 0 THEN END;
  976.            IF Windows.DeleteObject(hSTARS[i].hClipRgn) # 0 THEN END;
  977.        END; (* for i *)
  978.        IF Windows.DeleteObject(hFloorRgn) # 0 THEN END;
  979.        IF Windows.DeleteObject(hClientRgn) # 0 THEN END;
  980.        IF Windows.DeleteObject(hTankRgn) # 0 THEN END;
  981. END QuickDeleteRgns;
  982.  
  983.  
  984. PROCEDURE StopAllTimers(hWnd : Windows.HWND);
  985. BEGIN
  986.  
  987.       IF Windows.KillTimer(hWnd,FISHMOVE) = 0 THEN END;
  988.       IF Windows.KillTimer(hWnd,BUBBLEMOVE) = 0 THEN END;
  989.       IF Windows.KillTimer(hWnd,SETRANDOM) = 0 THEN END;
  990.       IF Windows.KillTimer(hWnd,STARMOVE) = 0 THEN END;
  991.       IF Windows.KillTimer(hWnd,WEEDMOVE) = 0 THEN END;
  992.       IF Windows.KillTimer(hWnd,CHESTMOVE) = 0 THEN END;
  993.  
  994. END StopAllTimers;
  995.  
  996. PROCEDURE StartAllTimers(hWnd : Windows.HWND);
  997. VAR timerid : INTEGER;
  998. BEGIN
  999.       timerid := Windows.SetTimer(hWnd,FISHMOVE,FISHTIMER,Windows.FARPROC(0));
  1000.       IF timerid = 0 THEN
  1001.          ApplFish.TimersLow(hWnd)
  1002.       END;
  1003.       timerid := Windows.SetTimer(hWnd,BUBBLEMOVE,BUBBLETIMER,Windows.FARPROC(0));
  1004.       IF timerid = 0 THEN
  1005.          ApplFish.TimersLow(hWnd)
  1006.       END;
  1007.       timerid := Windows.SetTimer(hWnd,SETRANDOM,RANDOMTIMER,Windows.FARPROC(0));
  1008.       IF timerid = 0 THEN
  1009.          ApplFish.TimersLow(hWnd)
  1010.       END;
  1011.       timerid := Windows.SetTimer(hWnd,STARMOVE,STARTIMER,Windows.FARPROC(0));
  1012.       IF timerid = 0 THEN
  1013.          ApplFish.TimersLow(hWnd)
  1014.       END;
  1015.       timerid := Windows.SetTimer(hWnd,WEEDMOVE,WEEDTIMER,Windows.FARPROC(0));
  1016.       IF timerid = 0 THEN
  1017.          ApplFish.TimersLow(hWnd)
  1018.       END;
  1019.       timerid := Windows.SetTimer(hWnd,CHESTMOVE,CHESTTIMER,Windows.FARPROC(0));
  1020.       IF timerid = 0 THEN
  1021.          ApplFish.TimersLow(hWnd)
  1022.       END;
  1023.  
  1024. END StartAllTimers;
  1025.  
  1026. PROCEDURE CreateInstance(hWnd : Windows.HWND);
  1027. BEGIN
  1028.  
  1029.   (* Load resources *)
  1030.     hFISHF1A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF1A)));
  1031.     hFISHF1B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF1B)));
  1032.     hFISHF1C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF1C)));
  1033.     hFISHF1D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF1D)));
  1034.     hFISHB1A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB1A)));
  1035.     hFISHB1B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB1B)));
  1036.     hFISHB1C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB1C)));
  1037.     hFISHB1D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB1D)));
  1038.     hFISHT1     := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHT1)));
  1039.  
  1040.     hFISHF2A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF2A)));
  1041.     hFISHF2B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF2B)));
  1042.     hFISHF2C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF2C)));
  1043.     hFISHF2D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF2D)));
  1044.     hFISHB2A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB2A)));
  1045.     hFISHB2B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB2B)));
  1046.     hFISHB2C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB2C)));
  1047.     hFISHB2D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB2D)));
  1048.     hFISHT2     := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHT2)));
  1049.  
  1050.     hFISHF3A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF3A)));
  1051.     hFISHF3B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF3B)));
  1052.     hFISHF3C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF3C)));
  1053.     hFISHF3D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF3D)));
  1054.     hFISHB3A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB3A)));
  1055.     hFISHB3B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB3B)));
  1056.     hFISHB3C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB3C)));
  1057.     hFISHB3D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB3D)));
  1058.     hFISHT3     := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHT3)));
  1059.  
  1060.     hFISHF4A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF4A)));
  1061.     hFISHF4B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF4B)));
  1062.     hFISHF4C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF4C)));
  1063.     hFISHF4D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF4D)));
  1064.     hFISHB4A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB4A)));
  1065.     hFISHB4B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB4B)));
  1066.     hFISHB4C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB4C)));
  1067.     hFISHB4D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB4D)));
  1068.     hFISHT4     := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHT4)));
  1069.  
  1070.     hFISHF5A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF5A)));
  1071.     hFISHF5B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF5B)));
  1072.     hFISHF5C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF5C)));
  1073.     hFISHF5D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF5D)));
  1074.     hFISHB5A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB5A)));
  1075.     hFISHB5B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB5B)));
  1076.     hFISHB5C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB5C)));
  1077.     hFISHB5D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB5D)));
  1078.     hFISHT5     := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHT5)));
  1079.  
  1080.     hFISHF6A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF6A)));
  1081.     hFISHF6B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF6B)));
  1082.     hFISHF6C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF6C)));
  1083.     hFISHF6D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF6D)));
  1084.     hFISHB6A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB6A)));
  1085.     hFISHB6B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB6B)));
  1086.     hFISHB6C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB6C)));
  1087.     hFISHB6D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB6D)));
  1088.     hFISHT6     := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHT6)));
  1089.  
  1090.     hFISHF7A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF7A)));
  1091.     hFISHF7B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF7B)));
  1092.     hFISHF7C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF7C)));
  1093.     hFISHF7D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHF7D)));
  1094.     hFISHB7A    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB7A)));
  1095.     hFISHB7B    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB7B)));
  1096.     hFISHB7C    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB7C)));
  1097.     hFISHB7D    := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHB7D)));
  1098.     hFISHT7     := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FISHT7)));
  1099.  
  1100.     hBUBBLEbmap := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(BUBBLE)));
  1101.     hBUBBLE1bmap := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(BUBBLE1)));
  1102.     hBUBBLE2bmap := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(BUBBLE2)));
  1103.     hBUBBLE3bmap := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(BUBBLE3)));
  1104.     hSTARS[1].hStar := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(STAR1)));
  1105.     hSTARS[2].hStar := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(STAR3)));
  1106.     hSTARS[3].hStar := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(STAR4)));
  1107.     hSTARS[4].hStar := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(STAR5)));
  1108.     hFLOORbmap := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(FLOOR)));
  1109.     hWEEDS[1].hWeed := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(WEED1)));
  1110.     hWEEDS[2].hWeed := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(WEED2)));
  1111.     hCHEST[1] := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(CHESTA)));
  1112.     hCHEST[2] := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(CHESTB)));
  1113.     hCHEST[3] := Windows.LoadBitmap( hInst, FarADDRESS(LONGCARD(CHESTC)));
  1114.  
  1115.     hAccTable := Windows.LoadAccelerators(hInst, "ApplAcclKeys");
  1116.  
  1117.     bubbleon := FALSE;
  1118.     hBUBBLES[1] := hBUBBLE1bmap;
  1119.     hBUBBLES[2] := hBUBBLE2bmap;
  1120.     hBUBBLES[3] := hBUBBLE3bmap;
  1121.     bubble := 1;
  1122.  
  1123.     ViewType := NORMAL;
  1124.  
  1125.     staron := FALSE;
  1126.     star := 1;
  1127.     weed := 1;
  1128.     chest := 1;
  1129.     FishHere := 1;
  1130.     CreateFishNode("Ugly",FishHere,TRUE,hFISHF1A,hFISHF1B,hFISHF1C,hFISHF1D,
  1131.     hFISHB1A,hFISHB1B,hFISHB1C,hFISHB1D,hFISHT1,450,100,FISH1X,FISH1Y,FASTSPEED,BACKWARDS,FISHMOVE);
  1132.     FishHere := 2;
  1133.     CreateFishNode("Chernobyl Eddie",FishHere,FALSE,hFISHF2A,hFISHF2B,hFISHF2C,hFISHF2D,
  1134.     hFISHB2A,hFISHB2B,hFISHB2C,hFISHB2D,hFISHT2,250,200,72,55,AVERAGESPEED,BACKWARDS,FISHMOVE);
  1135.     FishHere := 3;
  1136.     CreateFishNode("Tropical Trudy",FishHere,TRUE,hFISHF3A,hFISHF3B,hFISHF3C,hFISHF3D,
  1137.     hFISHB3A,hFISHB3B,hFISHB3C,hFISHB3D,hFISHT3,250,280,FISHX3X,FISHX3Y,AVERAGESPEED,FORWARDS,FISHMOVE);
  1138.     FishHere := 4;
  1139.     CreateFishNode("Angel",FishHere,TRUE,hFISHF4A,hFISHF4B,hFISHF4C,hFISHF4D,
  1140.     hFISHB4A,hFISHB4B,hFISHB4C,hFISHB4D,hFISHT4,200,50,FISHX1X,FISHX1Y,AVERAGESPEED,BACKWARDS,FISHMOVE);
  1141.     FishHere := 5;
  1142.     CreateFishNode("Red Ronnie",FishHere,TRUE,hFISHF5A,hFISHF5B,hFISHF5C,hFISHF5D,
  1143.     hFISHB5A,hFISHB5B,hFISHB5C,hFISHB5D,hFISHT5,50,80,FISHX2X,FISHX2Y,AVERAGESPEED,BACKWARDS,FISHMOVE);
  1144.     FishHere := 6;
  1145.     CreateFishNode("Goldie",FishHere,TRUE,hFISHF6A,hFISHF6B,hFISHF6C,hFISHF6D,
  1146.     hFISHB6A,hFISHB6B,hFISHB6C,hFISHB6D,hFISHT6,50,180,32,32,SLOWSPEED,BACKWARDS,FISHMOVE);
  1147.     FishHere := 7;
  1148.     CreateFishNode("The Gangers",FishHere,FALSE,hFISHF7A,hFISHF7B,hFISHF7C,hFISHF7D,
  1149.     hFISHB7A,hFISHB7B,hFISHB7C,hFISHB7D,hFISHT7,50,180,F1X,F1Y,FASTSPEED,BACKWARDS,FISHMOVE);
  1150.  
  1151.     FishMax := 7;
  1152.  
  1153.     RANDOMIZE;
  1154.  
  1155.     Windows.SetScrollRange(hWnd,Windows.SB_HORZ,0,SBHORZUNITS,0);
  1156.     Windows.SetScrollRange(hWnd,Windows.SB_VERT,0,SBVERTUNITS,0);
  1157.  
  1158.  
  1159. END CreateInstance;
  1160.  
  1161.  
  1162. (* The windows function *)
  1163.  
  1164. PROCEDURE MainWndProc( hWnd     : Windows.HWND;
  1165.                        message  : CARDINAL;
  1166.                        wParam   : CARDINAL;
  1167.                        lParam   : LONGINT ): LONGINT;
  1168.  
  1169. VAR
  1170.     ps: Windows.PAINTSTRUCT;
  1171.     hOldbmap  : Windows.HBITMAP;
  1172.     i,j : INTEGER;
  1173.     v : LONGCARD;
  1174.     hNewMenu,hTMenu : Windows.HMENU;
  1175.  
  1176. BEGIN
  1177.     CASE message OF
  1178.         | Windows.WM_COMMAND:
  1179.          CASE wParam OF
  1180.                 | IDM_START:
  1181.                     timerid := Windows.SetTimer(hWnd,FISHMOVE,FISHTIMER,Windows.FARPROC(0));
  1182.                     IF timerid = 0 THEN
  1183.                              ApplFish.TimersLow(hWnd)
  1184.                     END;
  1185.  
  1186.                     timerid := Windows.SetTimer(hWnd,BUBBLEMOVE,BUBBLETIMER,Windows.FARPROC(0));
  1187.                     IF timerid = 0 THEN
  1188.                              ApplFish.TimersLow(hWnd)
  1189.                     END;
  1190.                     IF NOT(randomset) THEN
  1191.                        randomset := TRUE;
  1192.                        timerid := Windows.SetTimer(hWnd,SETRANDOM,RANDOMTIMER,Windows.FARPROC(0));
  1193.                        IF timerid = 0 THEN
  1194.                                 ApplFish.TimersLow(hWnd)
  1195.                        END;
  1196.                     END;
  1197.                     IF (NOT(staron)) THEN
  1198.                        staron      := TRUE;
  1199.                        timerid := Windows.SetTimer(hWnd,STARMOVE,STARTIMER,Windows.FARPROC(0));
  1200.                        IF timerid = 0 THEN
  1201.                                 ApplFish.TimersLow(hWnd)
  1202.                        END;
  1203.                     END;
  1204.                     timerid := Windows.SetTimer(hWnd,WEEDMOVE,WEEDTIMER,Windows.FARPROC(0));
  1205.                     IF timerid = 0 THEN
  1206.                              ApplFish.TimersLow(hWnd)
  1207.                     END;
  1208.                     timerid := Windows.SetTimer(hWnd,CHESTMOVE,CHESTTIMER,Windows.FARPROC(0));
  1209.                     IF timerid = 0 THEN
  1210.                              ApplFish.TimersLow(hWnd)
  1211.                     END;
  1212.                     ReDrawAll(hWnd,CLIPREGION);
  1213.                 | IDM_DEBUG:
  1214.                     IF Windows.DestroyWindow(hWnd) = 0 THEN END;
  1215.                     ReDrawAll(hWnd,CLIPREGION);
  1216.  
  1217.                 | IDM_DESTROY:
  1218.                     IF Windows.DestroyWindow(hWnd) = 0 THEN END;
  1219.  
  1220.                 | IDM_ABOUT:
  1221.  
  1222.                     StopAllTimers(hWnd); (* When about is shown it sends a message bak here to start timers again *)
  1223.                     lpprocAbout := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.About)), hInst);
  1224.                     IF Windows.DialogBox( hInst, FarADDRESS(LONGCARD(ABOUTBOX)), hWnd, lpprocAbout ) # 0 THEN END;
  1225.                     Windows.FreeProcInstance(lpprocAbout);
  1226.  
  1227.                 | RESTART:
  1228.                     StartAllTimers(hWnd);
  1229.  
  1230.                 | IDM_SELECT:
  1231.  
  1232.                     lpOpenDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.Selec)), hInst);
  1233.                     IF Windows.DialogBox( hInst, FarADDRESS(LONGCARD(FISHSELECT)), hWnd, lpOpenDlg ) = 0 THEN END;
  1234.                     Windows.FreeProcInstance(lpOpenDlg);
  1235.  
  1236.                 | IDM_PLUSBUB:
  1237.  
  1238.                     IF BubbleMax < 10 THEN
  1239.                        BubbleMax := BubbleMax + 1;
  1240.                        BubbleHead[BubbleMax].X := RANDOM(XYRect.right);
  1241.                        BubbleHead[BubbleMax].Y := RANDOM(floorypos DIV 3) +(2* (CARDINAL(floorypos) DIV 3));
  1242.                        BubbleHead[BubbleMax].Speed := RANDOM(3) + 4;
  1243.                     END;
  1244.  
  1245.                 | IDM_MINUSBUB:
  1246.                     IF BubbleMax > 1 THEN
  1247.  
  1248.                        hOldbmap := Windows.SelectObject(hMemoryDC, hBUBBLEbmap);
  1249.                        IF Windows.BitBlt(hdc,BubbleHead[BubbleMax].X,BubbleHead[BubbleMax].Y,BUBBLE_X_XTENT,BUBBLE_Y_XTENT,hMemoryDC,0,0,Windows.BLACKNESS) # 0 THEN END;
  1250.                        BubbleMax := BubbleMax - 1;
  1251.                     END;
  1252.  
  1253.                 | IDM_CHANGEVIEW:
  1254.  
  1255.                   IF ViewType = NORMAL THEN
  1256.  
  1257.                     IF Windows.KillTimer(hWnd,FISHMOVE) = 0 THEN END;
  1258.                     IF Windows.KillTimer(hWnd,BUBBLEMOVE) = 0 THEN END;
  1259.                     IF Windows.KillTimer(hWnd,SETRANDOM) = 0 THEN END;
  1260.                     IF Windows.KillTimer(hWnd,STARMOVE) = 0 THEN END;
  1261.                     IF Windows.KillTimer(hWnd,WEEDMOVE) = 0 THEN END;
  1262.                     IF Windows.KillTimer(hWnd,CHESTMOVE) = 0 THEN END;
  1263.  
  1264.                      OldMapMode := Windows.SetMapMode(hdc,Windows.MM_ANISOTROPIC);
  1265.                      Windows.GetClientRect(hWnd,TempRect);
  1266.                      SbXPos := 0;
  1267.                      SbYPos := 0;
  1268.                      SbXInc := 0;
  1269.                      SbYInc := 0;
  1270.  
  1271.                      IF Windows.SetWindowOrg(hdc,0,0) = 0 THEN END;
  1272.                      IF Windows.SetScrollPos(hWnd,Windows.SB_HORZ,0,1) = 0 THEN END;
  1273.                      IF Windows.SetScrollPos(hWnd,Windows.SB_VERT,0,1) = 0 THEN END;
  1274.                      IF ReCalcRegions(hWnd) THEN
  1275.                         RETURN Windows.False
  1276.                      END;
  1277.  
  1278.                      IF Windows.SetWindowExt(hdc,TankWidth,TankDepth) = 0 THEN
  1279.                         IF Windows.MessageBox(hWnd,"Couldn't set wind ext","Warning",Windows.MB_OK) = 0 THEN END;
  1280.                      END;
  1281.                      IF Windows.SetViewportExt(hdc,TempRect.right,TempRect.bottom) = 0 THEN
  1282.                         IF Windows.MessageBox(hWnd,"Couldn't set viewport ext","Warning",Windows.MB_OK) = 0 THEN END;
  1283.                      END;
  1284.  
  1285.                     ReDrawAll(hWnd,CLIPREGION);
  1286.                     timerid := Windows.SetTimer(hWnd,FISHMOVE,FISHTIMER,Windows.FARPROC(0));
  1287.                     IF timerid = 0 THEN
  1288.                              ApplFish.TimersLow(hWnd)
  1289.                     END;
  1290.  
  1291.                     timerid := Windows.SetTimer(hWnd,BUBBLEMOVE,BUBBLETIMER,Windows.FARPROC(0));
  1292.                     IF timerid = 0 THEN
  1293.                              ApplFish.TimersLow(hWnd)
  1294.                     END;
  1295.  
  1296.                     timerid := Windows.SetTimer(hWnd,SETRANDOM,RANDOMTIMER,Windows.FARPROC(0));
  1297.                     IF timerid = 0 THEN
  1298.                              ApplFish.TimersLow(hWnd)
  1299.                     END;
  1300.  
  1301.                     timerid := Windows.SetTimer(hWnd,STARMOVE,STARTIMER,Windows.FARPROC(0));
  1302.                     IF timerid = 0 THEN
  1303.                              ApplFish.TimersLow(hWnd)
  1304.                     END;
  1305.  
  1306.                     timerid := Windows.SetTimer(hWnd,WEEDMOVE,WEEDTIMER,Windows.FARPROC(0));
  1307.                     IF timerid = 0 THEN
  1308.                              ApplFish.TimersLow(hWnd)
  1309.                     END;
  1310.  
  1311.                     timerid := Windows.SetTimer(hWnd,CHESTMOVE,CHESTTIMER,Windows.FARPROC(0));
  1312.                     IF timerid = 0 THEN
  1313.                              ApplFish.TimersLow(hWnd)
  1314.                     END;
  1315.  
  1316.                     ViewType := FIT
  1317.  
  1318.                   ELSE
  1319.  
  1320.                      IF Windows.SetMapMode(hdc,OldMapMode) = 0 THEN END;
  1321.                      IF Windows.SetWindowExt(hdc,1,1) = 0 THEN END;
  1322.                      IF Windows.SetViewportExt(hdc,1,1) = 0 THEN END;
  1323.  
  1324.                      Windows.GetClientRect(hWnd,XYRect);
  1325.                      RealXYRect:= XYRect;
  1326.                      ReDrawAll(hWnd,CLIPREGION);
  1327.                      ViewType := NORMAL;
  1328.                   END;
  1329.  
  1330.                 | IDM_DEFAULT:
  1331.  
  1332.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1333.                      FishHead[1].status := TRUE;
  1334.                      IF Windows.CheckMenuItem(hTMenu,IDM_FISH1,Windows.MF_CHECKED) = 0 THEN END;
  1335.                      FishHead[2].status := FALSE;
  1336.                      IF Windows.CheckMenuItem(hTMenu,IDM_FISH2,Windows.MF_UNCHECKED) = 0 THEN END;
  1337.                      FishHead[3].status := TRUE;
  1338.                      IF Windows.CheckMenuItem(hTMenu,IDM_FISH3,Windows.MF_CHECKED) = 0 THEN END;
  1339.                      FishHead[4].status := TRUE;
  1340.                      IF Windows.CheckMenuItem(hTMenu,IDM_FISH4,Windows.MF_CHECKED) = 0 THEN END;
  1341.                      FishHead[5].status := TRUE;
  1342.                      IF Windows.CheckMenuItem(hTMenu,IDM_FISH5,Windows.MF_CHECKED) = 0 THEN END;
  1343.                      FishHead[6].status := TRUE;
  1344.                      IF Windows.CheckMenuItem(hTMenu,IDM_FISH6,Windows.MF_CHECKED) = 0 THEN END;
  1345.                      FishHead[7].status := FALSE;
  1346.                      IF Windows.CheckMenuItem(hTMenu,IDM_FISH7,Windows.MF_UNCHECKED) = 0 THEN END;
  1347.                      ReDrawAll(hWnd,CLIPREGION);
  1348.  
  1349.                   | IDM_FISH1:
  1350.  
  1351.                      StopAllTimers(hWnd); (* dialog function will restart timers when it is ready *)
  1352.                      FishSelected := 1;
  1353.                      lpLifeDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.LifeInfo)), WMain.hInst);
  1354.                      IF Windows.DialogBox( WMain.hInst, FarADDRESS(LONGCARD(LIFEDATABOX)), hWnd, lpLifeDlg ) # 0 THEN END;
  1355.                      Windows.FreeProcInstance(lpLifeDlg);
  1356.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1357.  
  1358.                      IF FishHead[1].status = TRUE THEN
  1359.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH1,Windows.MF_CHECKED) = 0 THEN END;
  1360.                      ELSE
  1361.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH1,Windows.MF_UNCHECKED) = 0 THEN END;
  1362.                      END;
  1363.                      ReDrawAll(hWnd,CLIPREGION);
  1364.  
  1365.                   | IDM_FISH2:
  1366.  
  1367.                      StopAllTimers(hWnd);
  1368.                      FishSelected := 2;
  1369.  
  1370.                      lpLifeDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.LifeInfo)), WMain.hInst);
  1371.                      IF Windows.DialogBox( WMain.hInst, FarADDRESS(LONGCARD(LIFEDATABOX)), hWnd, lpLifeDlg ) # 0 THEN END;
  1372.                      Windows.FreeProcInstance(lpLifeDlg);
  1373.  
  1374.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1375.  
  1376.                      IF FishHead[2].status = TRUE THEN
  1377.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH2,Windows.MF_CHECKED) = 0 THEN END;
  1378.                      ELSE
  1379.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH2,Windows.MF_UNCHECKED) = 0 THEN END;
  1380.                      END;
  1381.                      ReDrawAll(hWnd,CLIPREGION);
  1382.  
  1383.                   | IDM_FISH3:
  1384.  
  1385.                      StopAllTimers(hWnd);
  1386.                      FishSelected := 3;
  1387.                      lpLifeDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.LifeInfo)), WMain.hInst);
  1388.                      IF Windows.DialogBox( WMain.hInst, FarADDRESS(LONGCARD(LIFEDATABOX)), hWnd, lpLifeDlg ) # 0 THEN END;
  1389.                      Windows.FreeProcInstance(lpLifeDlg);
  1390.  
  1391.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1392.  
  1393.                      IF FishHead[3].status = TRUE THEN
  1394.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH3,Windows.MF_CHECKED) = 0 THEN END;
  1395.                      ELSE
  1396.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH3,Windows.MF_UNCHECKED) = 0 THEN END;
  1397.                      END;
  1398.                      ReDrawAll(hWnd,CLIPREGION);
  1399.  
  1400.                   | IDM_FISH4:
  1401.  
  1402.                      StopAllTimers(hWnd);
  1403.                      FishSelected := 4;
  1404.                      lpLifeDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.LifeInfo)), WMain.hInst);
  1405.                      IF Windows.DialogBox( WMain.hInst, FarADDRESS(LONGCARD(LIFEDATABOX)), hWnd, lpLifeDlg ) # 0 THEN END;
  1406.                      Windows.FreeProcInstance(lpLifeDlg);
  1407.  
  1408.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1409.  
  1410.                      IF FishHead[4].status = TRUE THEN
  1411.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH4,Windows.MF_CHECKED) = 0 THEN END;
  1412.                      ELSE
  1413.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH4,Windows.MF_UNCHECKED) = 0 THEN END;
  1414.                      END;
  1415.                      ReDrawAll(hWnd,CLIPREGION);
  1416.  
  1417.                   | IDM_FISH5:
  1418.  
  1419.                      StopAllTimers(hWnd);
  1420.                      FishSelected := 5;
  1421.                      lpLifeDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.LifeInfo)), WMain.hInst);
  1422.                      IF Windows.DialogBox( WMain.hInst, FarADDRESS(LONGCARD(LIFEDATABOX)), hWnd, lpLifeDlg ) # 0 THEN END;
  1423.                      Windows.FreeProcInstance(lpLifeDlg);
  1424.  
  1425.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1426.  
  1427.                      IF FishHead[5].status = TRUE THEN
  1428.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH5,Windows.MF_CHECKED) = 0 THEN END;
  1429.                      ELSE
  1430.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH5,Windows.MF_UNCHECKED) = 0 THEN END;
  1431.                      END;
  1432.                      ReDrawAll(hWnd,CLIPREGION);
  1433.  
  1434.                   | IDM_FISH6:
  1435.  
  1436.                      StopAllTimers(hWnd);
  1437.                      FishSelected := 6;
  1438.                      lpLifeDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.LifeInfo)), WMain.hInst);
  1439.                      IF Windows.DialogBox( WMain.hInst, FarADDRESS(LONGCARD(LIFEDATABOX)), hWnd, lpLifeDlg ) # 0 THEN END;
  1440.                      Windows.FreeProcInstance(lpLifeDlg);
  1441.  
  1442.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1443.  
  1444.                      IF FishHead[6].status = TRUE THEN
  1445.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH6,Windows.MF_CHECKED) = 0 THEN END;
  1446.                      ELSE
  1447.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH6,Windows.MF_UNCHECKED) = 0 THEN END;
  1448.                      END;
  1449.                      ReDrawAll(hWnd,CLIPREGION);
  1450.  
  1451.                 | IDM_FISH7:
  1452.                      StopAllTimers(hWnd);
  1453.                      FishSelected := 7;
  1454.                      lpLifeDlg := Windows.MakeProcInstance( Windows.FARPROC(FarADR(ApplDlg.LifeInfo)), WMain.hInst);
  1455.                      IF Windows.DialogBox( WMain.hInst, FarADDRESS(LONGCARD(LIFEDATABOX)), hWnd, lpLifeDlg ) # 0 THEN END;
  1456.                      Windows.FreeProcInstance(lpLifeDlg);
  1457.  
  1458.                      hTMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  1459.  
  1460.                      IF FishHead[7].status = TRUE THEN
  1461.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH7,Windows.MF_CHECKED) = 0 THEN END;
  1462.                      ELSE
  1463.                         IF Windows.CheckMenuItem(hTMenu,IDM_FISH7,Windows.MF_UNCHECKED) = 0 THEN END;
  1464.                      END;
  1465.                      ReDrawAll(hWnd,CLIPREGION);
  1466.  
  1467.  
  1468.                 ELSE           (* End of menu option selections *)
  1469.  
  1470.                     RETURN Windows.DefWindowProc( hWnd, message, wParam, lParam);
  1471.                                (* If option not known pass on to windows *)
  1472.                 END;
  1473.  
  1474.          | SPECIAL_CHANGE:
  1475.  
  1476.                StartAllTimers(hWnd);
  1477.                RETURN (1);
  1478.  
  1479.          | INIT_INSTANCES:
  1480.  
  1481.                ApplFish.ReInitInstances(hWnd,hdc,CARDINAL(wParam),CARDINAL(lParam));
  1482.  
  1483.  
  1484.          | Windows.WM_TIMER:
  1485.            CASE wParam OF
  1486.  
  1487.            | IDM_DESTROY:
  1488.              IF Windows.DestroyWindow(hWnd) = 0 THEN END;
  1489.  
  1490.            | FISHMOVE:
  1491.  
  1492.              FishHere := 1;
  1493.              WHILE (FishHere <=FishMax) DO
  1494.  
  1495.               IF FishHead[FishHere].status THEN
  1496.  
  1497.                   IF ((FishHead[FishHere].speedx < 0) AND (FishHead[FishHere].pspeedx >= 0)) OR
  1498.                      ((FishHead[FishHere].speedx > 0) AND (FishHead[FishHere].pspeedx <= 0)) THEN
  1499.                      hOldbmap := Windows.SelectObject(hMemoryDC,FishHead[FishHere].turnbmap);
  1500.                      IF Windows.BitBlt(hdc,FishHead[FishHere].xpos,FishHead[FishHere].ypos,
  1501.                                        FishHead[FishHere].xextent,FishHead[FishHere].yextent,
  1502.                                        hMemoryDC,0,0,Windows.SRCCOPY) = 0 THEN
  1503.                      END;
  1504.                   END;
  1505.  
  1506.                   IF FishHead[FishHere].speedx > 0 THEN
  1507.                      IF Windows.BitBlt(hdc,FishHead[FishHere].xpos,FishHead[FishHere].ypos,
  1508.                                        FishHead[FishHere].speedx,FishHead[FishHere].yextent,hMemoryDC,0,0,
  1509.                                        Windows.BLACKNESS) # 0 THEN END;
  1510.                   END;
  1511.  
  1512.                   IF FishHead[FishHere].speedx < 0 THEN
  1513.                      IF Windows.BitBlt(hdc,FishHead[FishHere].xpos+FishHead[FishHere].xextent+INTEGER(FishHead[FishHere].speedx),
  1514.                                        FishHead[FishHere].ypos, -FishHead[FishHere].speedx,FishHead[FishHere].yextent,
  1515.                                        hMemoryDC,0,0,Windows.BLACKNESS) # 0 THEN END;
  1516.                   END;
  1517.  
  1518.                   FishHead[FishHere].pspeedx := FishHead[FishHere].speedx;
  1519.                   FishHead[FishHere].pspeedy := FishHead[FishHere].speedy;
  1520.  
  1521.                   IF FishHead[FishHere].xpos < RealXYRect.left-FishHead[FishHere].xextent THEN
  1522.                          FishHead[FishHere].xpos := RealXYRect.right
  1523.                   END;
  1524.  
  1525.                   IF FishHead[FishHere].xpos > RealXYRect.right THEN
  1526.                          FishHead[FishHere].xpos := RealXYRect.left-FishHead[FishHere].xextent
  1527.                   END;
  1528.  
  1529.                   FishHead[FishHere].xpos := FishHead[FishHere].xpos + INTEGER(FishHead[FishHere].speedx);
  1530.                   FishHead[FishHere].ypos := FishHead[FishHere].ypos + INTEGER(FishHead[FishHere].speedy);
  1531.  
  1532.                   IF FishHead[FishHere].ypos > RealXYRect.bottom THEN FishHead[FishHere].ypos :=
  1533.                                                                       RealXYRect.top-FishHead[FishHere].yextent
  1534.                   END;
  1535.  
  1536.                   IF FishHead[FishHere].ypos < RealXYRect.top-FishHead[FishHere].yextent THEN
  1537.                           FishHead[FishHere].ypos := RealXYRect.bottom
  1538.                   END;
  1539.  
  1540.                   IF FishHead[FishHere].bmapno = 4 THEN
  1541.                      FishHead[FishHere].bmapno := 1
  1542.                   ELSE
  1543.                      INC(FishHead[FishHere].bmapno)
  1544.                   END;
  1545.  
  1546.                   hOldbmap := Windows.SelectObject(hMemoryDC, FishHead[FishHere].bmap[FishHead[FishHere].direction,
  1547.                                                    FishHead[FishHere].bmapno]);
  1548.  
  1549.                   IF Windows.BitBlt(hdc,FishHead[FishHere].xpos,FishHead[FishHere].ypos,
  1550.                                     FishHead[FishHere].xextent,FishHead[FishHere].yextent,hMemoryDC,
  1551.                                     0,0,Windows.SRCCOPY) # 0 THEN END;
  1552.  
  1553.  
  1554.                   IF FishHead[FishHere].Instances > 0 THEN
  1555.                       ApplFish.AnimateOtherInstances(hdc,hMemoryDC,FishHead[FishHere])
  1556.                   END;
  1557.  
  1558.              END;   (* if status *)
  1559.              FishHere := FishHere+1;
  1560.            END; (* DO *)
  1561.  
  1562.            FishHere := 1;
  1563.  
  1564.            WHILE (FishHere <= FishMax) DO (* output again, ORing the bmaps to reduce flicker *)
  1565.  
  1566.             IF FishHead[FishHere].status THEN
  1567.  
  1568.               hOldbmap := Windows.SelectObject(hMemoryDC, FishHead[FishHere].bmap[FishHead[FishHere].direction,
  1569.                                                FishHead[FishHere].bmapno]);
  1570.               IF Windows.BitBlt(hdc,FishHead[FishHere].xpos,FishHead[FishHere].ypos,
  1571.                                 FishHead[FishHere].xextent,FishHead[FishHere].yextent,hMemoryDC,0,0,Windows.SRCPAINT) # 0 THEN END;
  1572.  
  1573.               IF FishHead[FishHere].Instances > 0 THEN
  1574.                  ApplFish.ReOutputOtherInstances(FishHead[FishHere],hMemoryDC,hdc)
  1575.               END;
  1576.             END;
  1577.             FishHere := FishHere+1
  1578.            END;
  1579.            FishHere := 1;
  1580. (* here *)
  1581.  
  1582.          | BUBBLEMOVE:
  1583.  
  1584.               BubbleHere := 1;
  1585.               hOldbmap := Windows.SelectObject(hMemoryDC, hBUBBLEbmap);
  1586.               WHILE (BubbleHere <= BubbleMax) DO
  1587.                  IF Windows.BitBlt(hdc,BubbleHead[BubbleHere].X,BubbleHead[BubbleHere].Y,BUBBLE_X_XTENT,BUBBLE_Y_XTENT,hMemoryDC,0,0,Windows.BLACKNESS) # 0 THEN END;
  1588.  
  1589.                  IF BubbleHead[BubbleHere].Y < RealXYRect.top THEN
  1590.                     BubbleHead[BubbleHere].Y := RealXYRect.bottom + INTEGER(RANDOM(50));
  1591.                     BubbleHead[BubbleHere].X := RANDOM(XYRect.right)+CARDINAL(Windows.LOWORD(Windows.GetWindowOrg(hdc)));
  1592.                  ELSE
  1593.                     BubbleHead[BubbleHere].Y := BubbleHead[BubbleHere].Y - INTEGER(BubbleHead[BubbleHere].Speed);
  1594.                  END;
  1595.                  IF Windows.BitBlt(hdc,BubbleHead[BubbleHere].X,BubbleHead[BubbleHere].Y,BUBBLE_X_XTENT,BUBBLE_Y_XTENT,hMemoryDC,0,0,Windows.SRCPAINT) # 0 THEN END;
  1596.                  BubbleHere := BubbleHere+1
  1597.               END;
  1598.           | SETRANDOM:
  1599.               i := ClipRgnType; (* need to invalidate an area or menu won't show *)
  1600.               ClipRgnType := 99;
  1601.               SetRectInvalid(hWnd,0,0,1,1);
  1602.               ClipRgnType:=i;
  1603.  
  1604.               FishHere := 1;
  1605.               WHILE (FishHere <= FishMax) DO
  1606.                IF FishHead[FishHere].status THEN
  1607.                  randomy := RANDOM(5);
  1608.                  FishHead[FishHere].pspeedx := FishHead[FishHere].speedx;
  1609.                  FishHead[FishHere].pspeedy := FishHead[FishHere].speedy;
  1610.                  CASE randomy OF
  1611.                       | 0 :  FishHead[FishHere].speedy := -1;Increase(FishHead[FishHere].speedx);
  1612.                       | 1 :  FishHead[FishHere].speedy := 1;FishHead[FishHere].speedx := 0;
  1613.                       | 2 :  FishHead[FishHere].speedx := FishHead[FishHere].basespeed;FishHead[FishHere].direction:=FORWARDS;FishHead[FishHere].speedy := 0;
  1614.                       | 3 :  FishHead[FishHere].speedx := -FishHead[FishHere].basespeed;FishHead[FishHere].direction:=BACKWARDS;FishHead[FishHere].speedy := 0;
  1615.                  END;
  1616.                  IF FishHead[FishHere].Instances > 0 THEN
  1617.                     ApplFish.RandomizeInstances(FishHead[FishHere]);
  1618.                  END
  1619.                END;
  1620.                FishHere := FishHere+1;
  1621.               END;
  1622.               FishHere := 1;
  1623.           | STARMOVE:
  1624.               prevstar := star;
  1625.               IF star = 4 THEN
  1626.                  star := 1
  1627.               ELSE
  1628.                  star := star + 1
  1629.               END;
  1630.                IF Windows.SelectClipRgn(hdc,hSTARS[prevstar].hStarRgn) = 0 THEN END;
  1631.                hOldbmap := Windows.SelectObject(hMemoryDC,hSTARS[star].hStar);
  1632.                IF Windows.BitBlt(hdc,STARXPOS,starypos,STARXSIZE,STARYSIZE,hMemoryDC,0,0,Windows.BLACKNESS) # 0 THEN END;
  1633.                IF Windows.SelectClipRgn(hdc,hSTARS[star].hStarRgn) = 0 THEN END;
  1634.                IF Windows.BitBlt(hdc,STARXPOS,starypos,STARXSIZE,STARYSIZE,hMemoryDC,0,0,Windows.SRCCOPY) # 0 THEN END;
  1635.               ClipRgnType := CLIPREGION;
  1636.               IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = Windows.ERROR THEN END;
  1637.  
  1638.           | WEEDMOVE:
  1639.               prevweed := weed;
  1640.               IF weed = MAXWEEDS THEN
  1641.                  weed := 1
  1642.               ELSE
  1643.                  weed := weed + 1
  1644.               END;
  1645.               ClipRgnType := WEEDREGION;
  1646.                IF Windows.SelectClipRgn(hdc,hFloorRgn) = 0 THEN END;
  1647.                hOldbmap := Windows.SelectObject(hMemoryDC,hWEEDS[weed].hWeed);
  1648.                IF Windows.BitBlt(hdc,WEEDXPOS,weedypos,WEEDXSIZE,WEEDYSIZE,hMemoryDC,0,0,Windows.SRCCOPY) # 0 THEN END;
  1649.               ClipRgnType := CLIPREGION;
  1650.               IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = Windows.ERROR THEN END;
  1651.  
  1652.           | CHESTMOVE:
  1653.               IF chest = 3 THEN
  1654.                  chest := 1
  1655.               ELSE
  1656.                  chest := chest + 1
  1657.               END;
  1658.               ClipRgnType := FLOORREGION;
  1659.                IF Windows.SelectClipRgn(hdc,hFloorRgn) = 0 THEN END;
  1660.                hOldbmap := Windows.SelectObject(hMemoryDC,hCHEST[chest]);
  1661.                IF Windows.BitBlt(hdc,CHESTXPOS,chestypos,CHESTXXTENT,CHESTYXTENT,hMemoryDC,0,0,Windows.SRCCOPY) # 0 THEN END;
  1662.               ClipRgnType := CLIPREGION;
  1663.               IF Windows.SelectClipRgn(hdc,hSTARS[star].hClipRgn) = Windows.ERROR THEN END;
  1664.  
  1665.            END;
  1666.          | Windows.WM_CREATE:
  1667.             CreateInstance(hWnd);
  1668.  
  1669.          | Windows.WM_HSCROLL:
  1670.             Windows.GetClientRect(hWnd,TempRect);
  1671.             SbXPos := Windows.GetScrollPos(hWnd,Windows.SB_HORZ);
  1672.             WindowOrg := Windows.GetWindowOrg(hdc);
  1673.             CASE wParam OF
  1674.                  | Windows.SB_LINEUP:
  1675.                    IF SbXPos > 0 THEN
  1676.                       SbXPos := SbXPos -1;
  1677.                       SbXInc := ((TankWidth-TempRect.right) * SbXPos) DIV SBHORZUNITS;
  1678.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(LONGCARD(SbXInc)),Windows.HIWORD(WindowOrg)) = 0 THEN END;
  1679.                       IF Windows.SetScrollPos(hWnd,Windows.SB_HORZ,SbXPos,1) = 0 THEN END;
  1680.                    END;
  1681.                  | Windows.SB_LINEDOWN:
  1682.                    IF SbXPos < SBHORZUNITS THEN
  1683.                       SbXPos := SbXPos +1;
  1684.                       SbXInc := ((TankWidth-TempRect.right) * SbXPos) DIV SBHORZUNITS;
  1685.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(LONGCARD(SbXInc)),Windows.HIWORD(WindowOrg)) = 0 THEN END;
  1686.                       IF Windows.SetScrollPos(hWnd,Windows.SB_HORZ,SbXPos,1) = 0 THEN END;
  1687.                    END;
  1688.                  | Windows.SB_PAGEUP:
  1689.                    IF SbXPos > 0 THEN
  1690.                       IF (TankWidth DIV TempRect.right) = 0 THEN
  1691.                          SbXPos := 0
  1692.                       ELSE
  1693.                          SbXPos := SbXPos - (SBHORZUNITS DIV (TankWidth DIV TempRect.right));
  1694.                                           (* Calc how many units a page up would be *)
  1695.                          IF SbXPos < 0 THEN
  1696.                             SbXPos := 0
  1697.                          END;
  1698.                       END;
  1699.                       SbXInc := ((TankWidth-TempRect.right) * SbXPos) DIV SBHORZUNITS;
  1700.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(LONGCARD(SbXInc)),Windows.HIWORD(WindowOrg)) = 0 THEN END;
  1701.                       IF Windows.SetScrollPos(hWnd,Windows.SB_HORZ,SbXPos,1) = 0 THEN END;
  1702.                    END;
  1703.                  | Windows.SB_PAGEDOWN:
  1704.                    IF SbXPos < SBHORZUNITS THEN
  1705.                       IF (TankWidth DIV TempRect.right) = 0 THEN
  1706.                          SbXPos := SBHORZUNITS
  1707.                       ELSE
  1708.                          SbXPos := SbXPos + ( SBHORZUNITS DIV (TankWidth DIV TempRect.right));
  1709.                                    (* Calc how many units a page down would be *)
  1710.                          IF SbXPos > SBHORZUNITS THEN
  1711.                             SbXPos := SBHORZUNITS
  1712.                          END;
  1713.                       END;
  1714.                       SbXInc := ((TankWidth-TempRect.right) * SbXPos) DIV SBHORZUNITS;
  1715.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(LONGCARD(SbXInc)),Windows.HIWORD(WindowOrg)) = 0 THEN END;
  1716.                       IF Windows.SetScrollPos(hWnd,Windows.SB_HORZ,SbXPos,1) = 0 THEN END;
  1717.                    END;
  1718.                  | Windows.SB_THUMBPOSITION:
  1719.                       SbXPos := INTEGER(Windows.LOWORD(lParam));
  1720.                       SbXInc := ((TankWidth-TempRect.right) * SbXPos) DIV SBHORZUNITS;
  1721.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(LONGCARD(SbXInc)),Windows.HIWORD(WindowOrg)) = 0 THEN END;
  1722.                       IF Windows.SetScrollPos(hWnd,Windows.SB_HORZ,SbXPos,1) = 0 THEN END;
  1723.  
  1724.             END;
  1725.             IF (wParam = Windows.SB_LINEUP) OR
  1726.                (wParam = Windows.SB_LINEDOWN) OR
  1727.                (wParam = Windows.SB_PAGEUP) OR
  1728.                (wParam = Windows.SB_PAGEDOWN) OR
  1729.                (wParam = Windows.SB_THUMBPOSITION) THEN
  1730.                IF ReCalcRegions(hWnd) THEN
  1731.                   RETURN (Windows.False)
  1732.                END;
  1733.                RealXYRect := TempRect;
  1734.                Windows.OffsetRect(RealXYRect,
  1735.                                Windows.LOWORD(Windows.GetWindowOrg(hdc)),
  1736.                                Windows.HIWORD(Windows.GetWindowOrg(hdc)));
  1737.  
  1738.                ReDrawAll(hWnd,ClipRgnType);
  1739.             END;
  1740.  
  1741.          | Windows.WM_VSCROLL:
  1742.             Windows.GetClientRect(hWnd,TempRect);
  1743.             SbYPos := Windows.GetScrollPos(hWnd,Windows.SB_VERT);
  1744.             WindowOrg := Windows.GetWindowOrg(hdc);
  1745.             CASE wParam OF
  1746.                  | Windows.SB_LINEUP:
  1747.                    IF SbYPos > 0 THEN
  1748.                       SbYPos := SbYPos -1;
  1749.                       SbYInc := ((TankDepth-TempRect.bottom) * SbYPos) DIV SBVERTUNITS;
  1750.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(WindowOrg),Windows.LOWORD(LONGCARD(SbYInc))) = 0 THEN END;
  1751.                       IF Windows.SetScrollPos(hWnd,Windows.SB_VERT,SbYPos,1) = 0 THEN END;
  1752.                    END;
  1753.                  | Windows.SB_LINEDOWN:
  1754.                    IF SbYPos < SBVERTUNITS THEN
  1755.                       SbYPos := SbYPos+1;
  1756.                       SbYInc := ((TankDepth-TempRect.bottom) * SbYPos) DIV SBVERTUNITS;
  1757.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(WindowOrg),Windows.LOWORD(LONGCARD(SbYInc))) = 0 THEN END;
  1758.                       IF Windows.SetScrollPos(hWnd,Windows.SB_VERT,SbYPos,1) = 0 THEN END;
  1759.                    END;
  1760.                  | Windows.SB_PAGEUP:
  1761.                    IF SbYPos > 0 THEN
  1762.                       IF (TankDepth DIV TempRect.bottom) = 0 THEN (* in case div by zero *)
  1763.                          SbYPos := 0;
  1764.                       ELSE
  1765.                          SbYPos := SbYPos - (SBVERTUNITS DIV (TankDepth DIV TempRect.bottom)); (* Calc how many units a page up would be *)
  1766.                          IF SbYPos < 0 THEN
  1767.                             SbYPos := 0
  1768.                          END;
  1769.                       END;
  1770.                       SbYInc := ((TankDepth-TempRect.bottom) * SbYPos) DIV SBVERTUNITS;
  1771.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(WindowOrg),Windows.LOWORD(LONGCARD(SbYInc))) = 0 THEN END;
  1772.                       IF Windows.SetScrollPos(hWnd,Windows.SB_VERT,SbYPos,1) = 0 THEN END;
  1773.                    END;
  1774.                  | Windows.SB_PAGEDOWN:
  1775.                    IF SbYPos < SBVERTUNITS THEN
  1776.                       IF (TankDepth DIV TempRect.bottom) = 0 THEN
  1777.                          SbYPos := SBVERTUNITS
  1778.                       ELSE
  1779.                          SbYPos := SbYPos + (SBVERTUNITS DIV (TankDepth DIV TempRect.bottom)); (* Calc how many units a page down would be *)
  1780.                          IF SbYPos > SBVERTUNITS THEN
  1781.                             SbYPos := SBVERTUNITS
  1782.                          END;
  1783.                       END;
  1784.                       SbYInc := ((TankDepth-TempRect.bottom) * SbYPos) DIV SBVERTUNITS;
  1785.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(WindowOrg),Windows.LOWORD(LONGCARD(SbYInc))) = 0 THEN END;
  1786.                       IF Windows.SetScrollPos(hWnd,Windows.SB_VERT,SbYPos,1) = 0 THEN END;
  1787.                    END;
  1788.                  | Windows.SB_THUMBPOSITION:
  1789.                       SbYPos := INTEGER(Windows.LOWORD(lParam));
  1790.                       SbYInc := ((TankDepth-TempRect.bottom) * SbYPos) DIV SBVERTUNITS;
  1791.                       IF Windows.SetWindowOrg(hdc,Windows.LOWORD(WindowOrg),Windows.LOWORD(LONGCARD(SbYInc))) = 0 THEN END;
  1792.                       IF Windows.SetScrollPos(hWnd,Windows.SB_VERT,SbYPos,1) = 0 THEN END;
  1793.             END;
  1794.             IF (wParam = Windows.SB_LINEUP) OR
  1795.                (wParam = Windows.SB_LINEDOWN) OR
  1796.                (wParam = Windows.SB_PAGEUP) OR
  1797.                (wParam = Windows.SB_PAGEDOWN) OR
  1798.                (wParam = Windows.SB_THUMBPOSITION) THEN
  1799.                IF ReCalcRegions(hWnd) THEN
  1800.                   RETURN Windows.False
  1801.                END;
  1802.                RealXYRect := TempRect;
  1803.                Windows.OffsetRect(RealXYRect,
  1804.                                   Windows.LOWORD(Windows.GetWindowOrg(hdc)),
  1805.                                   Windows.HIWORD(Windows.GetWindowOrg(hdc)));
  1806.                ReDrawAll(hWnd,ClipRgnType);
  1807.             END;
  1808.  
  1809.          | Windows.WM_DESTROY:
  1810. (*          WHILE (FishHead # NIL) DO
  1811.               FishHere := FishHead;
  1812.               FishHead := FishHead^.NextFish;
  1813.               DEALLOCATE(FishHere,SIZE(FishHere))
  1814.             END;
  1815.             WHILE (BubbleHead # NIL) DO
  1816.               BubbleHere := BubbleHead;
  1817.               BubbleHead := BubbleHead^.NextBubble;
  1818.               DEALLOCATE(BubbleHere,SIZE(BubbleHere))
  1819.             END;
  1820.  
  1821. *)
  1822.             ApplFish.DeleteFishInstances;
  1823.             FOR i := 1 TO MAXSTARS DO
  1824.                 IF Windows.DeleteObject(hSTARS[i].hStarRgn) = 0 THEN END;
  1825.                 IF Windows.DeleteObject(hSTARS[i].hStar) # 0 THEN END;
  1826.                 IF Windows.DeleteObject(hSTARS[i].hClipRgn) # 0 THEN END;
  1827.             END; (* for i *)
  1828.             IF Windows.DeleteObject(hFloorRgn) # 0 THEN END;
  1829.             IF Windows.DeleteObject(hClientRgn) # 0 THEN END;
  1830.         (*    IF Windows.DeleteObject(hFishRgn) # 0 THEN END; *)
  1831.             IF Windows.DeleteObject(hTankRgn) # 0 THEN END;
  1832.             IF Windows.DeleteDC(hMemoryDC) # 0 THEN END;
  1833.             IF Windows.DeleteObject(hBUBBLEbmap) # 0 THEN END;
  1834.             IF Windows.DeleteObject(hBUBBLE3bmap) # 0 THEN END;
  1835.             IF Windows.DeleteObject(hBUBBLE1bmap) # 0 THEN END;
  1836.             IF Windows.DeleteObject(hBUBBLE2bmap) # 0 THEN END;
  1837.             IF Windows.DeleteObject(hFLOORbmap) # 0 THEN END;
  1838.             IF Windows.DeleteObject(hWEEDS[1].hWeed) # 0 THEN END;
  1839.             IF Windows.DeleteObject(hWEEDS[2].hWeed) # 0 THEN END;
  1840.             IF Windows.DeleteObject(hCHEST[1]) # 0 THEN END;
  1841.             IF Windows.DeleteObject(hCHEST[2]) # 0 THEN END;
  1842.             IF Windows.DeleteObject(hCHEST[3]) # 0 THEN END;
  1843.  
  1844.             IF Windows.DeleteObject(hFISHF1A) # 0 THEN END;
  1845.             IF Windows.DeleteObject(hFISHF1B) # 0 THEN END;
  1846.             IF Windows.DeleteObject(hFISHF1C) # 0 THEN END;
  1847.             IF Windows.DeleteObject(hFISHF1D) # 0 THEN END;
  1848.             IF Windows.DeleteObject(hFISHB1A) # 0 THEN END;
  1849.             IF Windows.DeleteObject(hFISHB1B) # 0 THEN END;
  1850.             IF Windows.DeleteObject(hFISHB1C) # 0 THEN END;
  1851.             IF Windows.DeleteObject(hFISHB1D) # 0 THEN END;
  1852.             IF Windows.DeleteObject(hFISHT1) # 0 THEN END;
  1853.  
  1854.             IF Windows.DeleteObject(hFISHF2A) # 0 THEN END;
  1855.             IF Windows.DeleteObject(hFISHF2B) # 0 THEN END;
  1856.             IF Windows.DeleteObject(hFISHF2C) # 0 THEN END;
  1857.             IF Windows.DeleteObject(hFISHF2D) # 0 THEN END;
  1858.             IF Windows.DeleteObject(hFISHB2A) # 0 THEN END;
  1859.             IF Windows.DeleteObject(hFISHB2B) # 0 THEN END;
  1860.             IF Windows.DeleteObject(hFISHB2C) # 0 THEN END;
  1861.             IF Windows.DeleteObject(hFISHB2D) # 0 THEN END;
  1862.             IF Windows.DeleteObject(hFISHT2) # 0 THEN END;
  1863.  
  1864.             IF Windows.DeleteObject(hFISHF3A) # 0 THEN END;
  1865.             IF Windows.DeleteObject(hFISHF3B) # 0 THEN END;
  1866.             IF Windows.DeleteObject(hFISHF3C) # 0 THEN END;
  1867.             IF Windows.DeleteObject(hFISHF3D) # 0 THEN END;
  1868.             IF Windows.DeleteObject(hFISHB3A) # 0 THEN END;
  1869.             IF Windows.DeleteObject(hFISHB3B) # 0 THEN END;
  1870.             IF Windows.DeleteObject(hFISHB3C) # 0 THEN END;
  1871.             IF Windows.DeleteObject(hFISHB3D) # 0 THEN END;
  1872.             IF Windows.DeleteObject(hFISHT3) # 0 THEN END;
  1873.  
  1874.             IF Windows.DeleteObject(hFISHF4A) # 0 THEN END;
  1875.             IF Windows.DeleteObject(hFISHF4B) # 0 THEN END;
  1876.             IF Windows.DeleteObject(hFISHF4C) # 0 THEN END;
  1877.             IF Windows.DeleteObject(hFISHF4D) # 0 THEN END;
  1878.             IF Windows.DeleteObject(hFISHB4A) # 0 THEN END;
  1879.             IF Windows.DeleteObject(hFISHB4B) # 0 THEN END;
  1880.             IF Windows.DeleteObject(hFISHB4C) # 0 THEN END;
  1881.             IF Windows.DeleteObject(hFISHB4D) # 0 THEN END;
  1882.             IF Windows.DeleteObject(hFISHT4) # 0 THEN END;
  1883.  
  1884.             IF Windows.DeleteObject(hFISHF5A) # 0 THEN END;
  1885.             IF Windows.DeleteObject(hFISHF5B) # 0 THEN END;
  1886.             IF Windows.DeleteObject(hFISHF5C) # 0 THEN END;
  1887.             IF Windows.DeleteObject(hFISHF5D) # 0 THEN END;
  1888.             IF Windows.DeleteObject(hFISHB5A) # 0 THEN END;
  1889.             IF Windows.DeleteObject(hFISHB5B) # 0 THEN END;
  1890.             IF Windows.DeleteObject(hFISHB5C) # 0 THEN END;
  1891.             IF Windows.DeleteObject(hFISHB5D) # 0 THEN END;
  1892.             IF Windows.DeleteObject(hFISHT5) # 0 THEN END;
  1893.  
  1894.             IF Windows.DeleteObject(hFISHF6A) # 0 THEN END;
  1895.             IF Windows.DeleteObject(hFISHF6B) # 0 THEN END;
  1896.             IF Windows.DeleteObject(hFISHF6C) # 0 THEN END;
  1897.             IF Windows.DeleteObject(hFISHF6D) # 0 THEN END;
  1898.             IF Windows.DeleteObject(hFISHB6A) # 0 THEN END;
  1899.             IF Windows.DeleteObject(hFISHB6B) # 0 THEN END;
  1900.             IF Windows.DeleteObject(hFISHB6C) # 0 THEN END;
  1901.             IF Windows.DeleteObject(hFISHB6D) # 0 THEN END;
  1902.             IF Windows.DeleteObject(hFISHT6) # 0 THEN END;
  1903.  
  1904.             IF Windows.DeleteObject(hFISHF7A) # 0 THEN END;
  1905.             IF Windows.DeleteObject(hFISHF7B) # 0 THEN END;
  1906.             IF Windows.DeleteObject(hFISHF7C) # 0 THEN END;
  1907.             IF Windows.DeleteObject(hFISHF7D) # 0 THEN END;
  1908.             IF Windows.DeleteObject(hFISHB7A) # 0 THEN END;
  1909.             IF Windows.DeleteObject(hFISHB7B) # 0 THEN END;
  1910.             IF Windows.DeleteObject(hFISHB7C) # 0 THEN END;
  1911.             IF Windows.DeleteObject(hFISHB7D) # 0 THEN END;
  1912.             IF Windows.DeleteObject(hFISHT7) # 0 THEN END;
  1913.  
  1914.             IF Windows.DeleteObject(hAccTable) # 0 THEN END;
  1915.  
  1916.             Windows.PostQuitMessage(0);
  1917.          | Windows.WM_PAINT:
  1918.             IF Windows.BeginPaint(hWnd, ps) # Windows.HDC(0) THEN END;
  1919.             MessagePaint(hWnd,ps.hdc,ps.rcPaint);
  1920.             Windows.EndPaint(hWnd, ps);
  1921.  
  1922.         ELSE
  1923.  
  1924.           IF (wParam = Windows.WM_SIZE) OR
  1925.              (wParam = Windows.SC_MAXIMIZE) OR
  1926.              (wParam = Windows.SC_ZOOM) THEN
  1927.             OldXYRect := XYRect;
  1928.             Windows.GetClientRect(hWnd,XYRect); (* client area may have changed *)
  1929.             IF Windows.EqualRect(OldXYRect,XYRect) = 0 THEN
  1930.                RealXYRect := XYRect;
  1931.                SbXPos := 0;
  1932.                SbYPos := 0;
  1933.                SbXInc := 0;
  1934.                SbYInc := 0;
  1935.                IF Windows.SetWindowOrg(hdc,0,0) = 0 THEN END;
  1936.                IF Windows.SetScrollPos(hWnd,Windows.SB_HORZ,0,1) = 0 THEN END;
  1937.                IF Windows.SetScrollPos(hWnd,Windows.SB_VERT,0,1) = 0 THEN END;
  1938.                IF ReCalcRegions(hWnd) THEN
  1939.                   RETURN Windows.False
  1940.                END;
  1941.                ReDrawAll(hWnd,CLIPREGION);
  1942.  
  1943.             END; (* if not equal rects *)
  1944.           END;
  1945.           RETURN Windows.DefWindowProc( hWnd, message, wParam, lParam);
  1946.         END;
  1947.     RETURN 0;
  1948. END MainWndProc;
  1949.  
  1950.  
  1951.  
  1952. (* This procedure called when the program is loaded for the first time *)
  1953.  
  1954. PROCEDURE DemoInit(hInstance: Windows.HANDLE): BOOLEAN;
  1955.  
  1956. VAR
  1957.   DemoClass: Windows.WNDCLASS;
  1958. BEGIN
  1959.  
  1960.   IF Windows.LoadString(hInstance, IDSNAME,szAppName, 10) # 0 THEN END;
  1961.   IF Windows.LoadString(hInstance, IDSABOUT,szAbout, 10) # 0 THEN END;
  1962.   MessageLength:= Windows.LoadString(hInstance, IDSTITLE,szMessage, 25);
  1963.   IF Windows.LoadString(hInstance, IDSDEFSPEC, szDefSpec, 13) # 0 THEN END;
  1964.   IF Windows.LoadString(hInstance, IDSDEFEXT, szDefExt, 4) # 0 THEN END;
  1965.  
  1966. (*  pDemoClass := Windows.PWNDCLASS(Windows.LocalAlloc( Windows.LPTR, SIZE(Windows.WNDCLASS))); *)
  1967.  
  1968.   DemoClass.hCursor := Windows.LoadCursor(Windows.HANDLE(0), FarADDRESS(Windows.IDC_ARROW));
  1969.   DemoClass.hIcon := 0;
  1970. (*  DemoClass.hIcon := Windows.LoadIcon(hInstance, FarADDRESS(LONGCARD(AQUAICON)));*)
  1971.   DemoClass.lpszMenuName := FarNIL;
  1972.   DemoClass.lpszClassName := Windows.LPSTR(FarADR(szAppName));
  1973.   DemoClass.hbrBackground := Windows.HBRUSH(Windows.GetStockObject(Windows.BLACK_BRUSH));
  1974.   DemoClass.hInstance:=hInstance;
  1975.   DemoClass.style := Windows.CS_HREDRAW + Windows.CS_VREDRAW + Windows.CS_OWNDC;
  1976.   DemoClass.lpfnWndProc := FarADR(MainWndProc);
  1977.  
  1978.   IF Windows.RegisterClass(DemoClass) = 0 THEN
  1979.         (* Initialization failed.
  1980.          * Windows will automatically deallocate all allocated memory. *)
  1981.     RETURN FALSE;
  1982.   END;
  1983. (*  IF Windows.LocalFree( Windows.HANDLE(pDemoClass)) # Windows.HANDLE(0) THEN END; *)
  1984.   RETURN TRUE;        (* Success *)
  1985. END DemoInit;
  1986.  
  1987.  
  1988. PROCEDURE WinMain(hInstance: Windows.HANDLE; hPrevInstance: Windows.HANDLE; lpszCmdLine: Windows.LPSTR; cmdShow: INTEGER): Windows.BOOL;
  1989.  
  1990. VAR
  1991.     msg: Windows.MSG;
  1992.     hWnd: Windows.HWND;
  1993.     hMenu: Windows.HWND;
  1994.     hApplMenu : Windows.HMENU;
  1995.     i,j       : INTEGER;
  1996.     jab : LONGCARD;
  1997.     ja : FarADDRESS;
  1998. BEGIN
  1999.     IF hPrevInstance = Windows.HANDLE(0) THEN
  2000.         (* Call initialization procedure if this is the first instance *)
  2001.         IF NOT DemoInit(hInstance) THEN
  2002.             RETURN INTEGER(FALSE);
  2003.         END;
  2004.     ELSE
  2005.         (* Copy data from previous instance *)
  2006.         IF Windows.GetInstanceData(hPrevInstance, NearADR(szAppName), 10) # 0 THEN END;
  2007.         IF Windows.GetInstanceData(hPrevInstance, NearADR(szAbout), 10) # 0 THEN END;
  2008.         IF Windows.GetInstanceData(hPrevInstance, NearADR(szMessage), 25) # 0 THEN END;
  2009.         IF Windows.GetInstanceData(hPrevInstance, NearADR(MessageLength), SIZE(INTEGER)) # 0 THEN END;
  2010.         IF Windows.GetInstanceData(hPrevInstance, NearADR(szDefSpec), 13) # 0 THEN END;
  2011.         IF Windows.GetInstanceData(hPrevInstance, NearADR(szDefExt), 4) # 0 THEN END;
  2012.     END;
  2013.  
  2014.     (* Load Menu from Resource file *)
  2015.     hApplMenu := Windows.LoadMenu (hInstance, "ApplMenu");
  2016.  
  2017.     hBrush := Windows.CreateSolidBrush(Windows.RGB(255,0,0));
  2018.  
  2019.     (* Save instance handle for DialogBox *)
  2020.     hInst := hInstance;
  2021.  
  2022.     hWnd := Windows.CreateWindow(Windows.LPSTR(FarADR(szAppName)),
  2023.                         szMessage,
  2024.                         Windows.WS_OVERLAPPEDWINDOW + Windows.WS_HSCROLL + Windows.WS_VSCROLL,
  2025.                         Windows.CW_USEDEFAULT,
  2026.                         Windows.CW_USEDEFAULT,
  2027.                         Windows.CW_USEDEFAULT,
  2028.                         Windows.CW_USEDEFAULT,
  2029.                         Windows.HWND(0),        (* no parent *)
  2030.                         hApplMenu,        (* use class menu *)
  2031.                         hInstance,     (* handle to window instance *)
  2032.                         FarNIL         (* no params to pass on *)
  2033.                         );
  2034.  
  2035.     hMenu:= Windows.GetSubMenu(Windows.GetMenu(hWnd),FISHOPTION);
  2036.     Windows.ChangeMenu(hMenu, 0, FarADR("Default"), IDM_DEFAULT, Windows.MF_APPEND + Windows.MF_STRING);
  2037.     Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  2038.     Windows.ChangeMenu(hMenu, 0, FarADDRESS(Windows.MAKELONG(hFISHF1A,0)), IDM_FISH1, Windows.MF_APPEND + Windows.MF_BITMAP + Windows.MF_CHECKED);
  2039.     Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  2040.     Windows.ChangeMenu(hMenu, 0, FarADDRESS(Windows.MAKELONG(hFISHF2A,0)), IDM_FISH2, Windows.MF_APPEND + Windows.MF_BITMAP + Windows.MF_UNCHECKED);
  2041.     Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  2042.     Windows.ChangeMenu(hMenu, 0, FarADDRESS(Windows.MAKELONG(hFISHF3A,0)), IDM_FISH3, Windows.MF_APPEND + Windows.MF_BITMAP + Windows.MF_CHECKED);
  2043.     Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  2044.     Windows.ChangeMenu(hMenu, 0, FarADDRESS(Windows.MAKELONG(hFISHF4A,0)), IDM_FISH4, Windows.MF_APPEND + Windows.MF_BITMAP + Windows.MF_CHECKED);
  2045.     Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  2046.     Windows.ChangeMenu(hMenu, 0, FarADDRESS(Windows.MAKELONG(hFISHF5A,0)), IDM_FISH5, Windows.MF_APPEND + Windows.MF_BITMAP + Windows.MF_CHECKED);
  2047.     Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  2048.     Windows.ChangeMenu(hMenu, 0, FarADDRESS(Windows.MAKELONG(hFISHF6A,0)), IDM_FISH6, Windows.MF_APPEND + Windows.MF_BITMAP + Windows.MF_CHECKED);
  2049.     Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  2050.     Windows.ChangeMenu(hMenu, 0, FarADDRESS(Windows.MAKELONG(hFISHF7A,0)), IDM_FISH7, Windows.MF_APPEND + Windows.MF_BITMAP + Windows.MF_UNCHECKED);
  2051.  
  2052.  
  2053.     hdc := Windows.GetDC(hWnd);
  2054.     hMemoryDC := Windows.CreateCompatibleDC(hdc);
  2055.  
  2056.     TankDepth := Windows.GetDeviceCaps(hdc,Windows.VERTRES);
  2057.     TankWidth := Windows.GetDeviceCaps(hdc,Windows.HORZRES);
  2058.     TankDepth := TankDepth-TANKDEPTHDIFF;
  2059.  
  2060.     Windows.GetClientRect(hWnd,XYRect);
  2061.  
  2062.     floorypos := TankDepth - FLOORYSIZE;
  2063.     weedypos := floorypos - 72;
  2064.     chestypos := floorypos + 8;
  2065.  
  2066.     hTankRgn := Windows.CreateRectRgn(0,0,TankWidth,TankDepth);
  2067.     IF hTankRgn = 0 THEN
  2068.        IF ApplFish.ResourcesLow(hWnd) THEN
  2069.           RETURN Windows.False
  2070.        END
  2071.     END;
  2072.  
  2073.     IF ReCalcFloorRegion(hWnd) THEN (* Resource problem *)
  2074.        RETURN (Windows.False)
  2075.     END;
  2076.     hFishRgn := Windows.CreateRectRgnIndirect(XYRect); (* Needs to be created just once for combine rgn *)
  2077.     IF hFishRgn = 0 THEN
  2078.        IF ApplFish.ResourcesLow(hWnd) THEN
  2079.           RETURN Windows.False
  2080.        END
  2081.     END;
  2082.     SetUpBubbles;  (* Needs Client Area info before setup *)
  2083.     FOR i := 1 TO 4 DO
  2084.         hSTARS[i].hClipRgn := Windows.CreateRectRgnIndirect(XYRect);
  2085.         IF hSTARS[i].hClipRgn = 0 THEN
  2086.            IF ApplFish.ResourcesLow(hWnd) THEN
  2087.               RETURN Windows.False
  2088.            END
  2089.         END
  2090.     END;
  2091.  
  2092.     RealXYRect := XYRect;
  2093.  
  2094.     IF (ResizeStarParams(hWnd)) THEN (* Then resource problem *) (* Also needs floor info *)
  2095.        RETURN(Windows.False) (* Also needs floor info *)
  2096.     END;
  2097.  
  2098.     hClientRgn := Windows.CreateRectRgn(0,0,TankWidth,TankDepth);
  2099.     IF hClientRgn = 0 THEN
  2100.        IF ApplFish.ResourcesLow(hWnd) THEN
  2101.           RETURN Windows.False
  2102.        END
  2103.     END;
  2104.  
  2105.     WindowOrg := Windows.GetWindowOrg(hdc);
  2106.  
  2107.     ClipRgnType := CLIENTREGION;
  2108.     IF Windows.SelectClipRgn(hdc,hClientRgn) = Windows.ERROR THEN END;
  2109.  
  2110.    (* Make window visible according to the way the app is activated *)
  2111.     IF Windows.ShowWindow(hWnd, cmdShow) # 0 THEN END;
  2112.     Windows.UpdateWindow(hWnd);
  2113.     IF Windows.PostMessage(hWnd,Windows.WM_COMMAND,IDM_START,0) = 0 THEN END;
  2114.  
  2115.  
  2116.     (* Polling messages from event queue *)
  2117.     WHILE (Windows.GetMessage(msg, Windows.HWND(0), 0, 0)) # 0 DO
  2118.        IF Windows.TranslateAccelerator(hWnd, hAccTable,msg) = 0 THEN END;
  2119.         IF Windows.TranslateMessage(msg) # 0 THEN END;
  2120.         IF Windows.DispatchMessage(msg) # 0 THEN END;
  2121.     END;
  2122.     RETURN msg.wParam;
  2123. END WinMain;
  2124.  
  2125.  
  2126.  
  2127. END WMain.
  2128.